How To Identify Cell Address VBA [duplicate] - vba

This question already has answers here:
Find last used cell in Excel VBA
(14 answers)
Closed 5 years ago.
How do I find the last line/Row of an edited document meaning new information will be added to the document without my knowledge and I still need to be able to identify its address. VBA

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
If you don't need VBA, then press Ctrl + Down Arrow in a column with continuous rows to bring you to the last row

Related

Use data_only=True when you load your workbook. (For example, workbook = openpyxl.load_workbook("yourxlsx.xlsx", data_only=True)) [duplicate]

This question already has answers here:
Python openpyxl data_only=True returning None
(7 answers)
Closed 1 year ago.
I am not able to print the computed cell value with this option. it is printing the formula instead of cell value.. can someone please help me on this.!!!!!!!!!!!!!!!!
sheet['L3'] = '=COUNTIF(B1:B431,"Resolved")'
now I want to print the L3 cell value to the screen
Python openpyxl data_only=True returning None
According the this thread, the formula needs to be evaluated by Excel before having its value cached.

Loop through current row cells and stop on next non zero value - leave that as active cell [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a file with very long rows of data. They are formulae and many of the results are zero values.
I would like a macro that will loop through the active row and stop at the next non-zero value cell, leaving that as the active cell.
This will save time scrolling through looking manually for the non-zeros and also avoid the human error of missing them as you scroll through.
I think (in pseudo code) I want something along the lines of:
For active cell To end of row
If value is zero then active cell x+1
Next
End if
End
I can't write VBA myself, just vaguely understand what it is doing by reading it and can copy and modify similar coding but I can't find anything close enough for this.
I haven't a clue how to declare the variables etc. at the top either.
I would really really appreciate some help with this. I have been struggling with it for months and I think it should probably be quite simple.
This question is going to be closed due to being too broad, because it is.
However, here is a short snippet i hope will help you and maybe others who wil google this issue in the future:
Public Sub StackOverflowExample()
Dim LastColumnNumber As Integer
'get the number of the last column with data in row of the currently selected cell
'we dont want to go through the entire row when data ends, only until the last cell with data
LastColumnNumber = ActiveSheet.Rows(ActiveCell.Row).SpecialCells(xlCellTypeLastCell).Column
'i is our iteration variable, will go from the number of the currently selected cell
'to the number of the last column with data. we start from the next cell each time
'otherwise the macro wont work if the selected cell has a non 0 value
For i = ActiveCell.Column + 1 To LastColumnNumber
'check if the value of cell with column number i on the current row is not 0
'Note: if you do a number comparison, empty cells' values will count as 0 as well
If ActiveSheet.Cells(ActiveCell.Row, i) <> 0 Then
'select the found cell, scroll the sheet to it and exit the FOR loop
ActiveSheet.Cells(ActiveCell.Row, i).Select
Application.Goto ActiveCell, True
Exit For
End If
Next i
End Sub

How to use Auto filter criteria from a cell reference on another workbook [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Need help in using vba to auto filter columns in a workbook but the filter criteria is in a cell reference on another workbook. To Start, i have 2 workbooks, the first is the report template where the macro is entered and the other is the data file that needs to be filtered.
You can reference reference cells in the (closed) template workbook in your Autofilter VBA statement. ExecuteExcel4Macro is of help here, permitting to evaluate a reference to another, closed workbook the same way it would be typed in a formula.
For example, to autofilter a range by cell B5 of the control sheet in the report template:
myRange.AutoFilter 1, ExecuteExcel4Macro("'C:\myPath\myfolder\[Report.xltx]control'!R5C2")
Notice that ExecuteExcel4Macro requires RC-style addresses, so use R5C2 for B5, R5C3 for C5 and R5C4 for D5...

VBA Code to add comment to changed cell [duplicate]

This question already has an answer here:
Excel: Add comment author using vba
(1 answer)
Closed 8 years ago.
I need to add a comment with original data to cell where data is changed.
Ex: 4 of 7 gets changed to 3 of 7 in a cell. I need the comment to show 4 of 7 so I can see what the original data was.
Is there a macro that can be written to automatically insert a comment with original data to all cells that have been changed?
Say you are working with Cell A1
Before you change the value of Cell A1, store it in a variable myVal, then write something along the following lines:
Range("A1").AddComment
Range("A1").Comment.Text Text:= myVal

Macro to Transfer Specific Table Content in MS Word 2007 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have around 50 word documents in an old format which I need to convert to a new format. I was thinking of having a new format template and copying needed numbered fields from the old format into the new format using a macro, and finally saving this new document.
I have numbered fields from 1 to 6 in the old format where some fields are in the header. I need these fields in the new format where the sequence is different.
I am a absolute beginner in macros and need to submit this tomorrow so would appreciate any help or advise urgently.
Word documents download links are mentioned below:
OLD FORMAT : http://www.scribd.com/R0cKyMan/d/90470134-Old-Format
NEW FORMAT : http://www.scribd.com/R0cKyMan/d/90473107-New-Format
So can u help me out with copy header fields. Thanks – R0cKy 3 mins ago
The tables in the Header have to be accessed in a different way.
When a table is in the body, you can use it like this
ActiveDocument.Tables(1).Cell(1, 1).Select
Selection.Copy
But to access the table which is in the Header you have to access the Section in which the Header is. In your case the table is in wdHeaderFooterPrimary
Try this
Option Explicit
Sub Sample()
'~~> Copies the 2nd Cell in the first row of a table which is in the Header
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 2).Select
Selection.Copy
'~~> Pastes it in say 1st cell in Row 1 of a table which is in the body
ActiveDocument.Tables(1).Cell(2, 3).Select
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Hope this gets you started.