How to select last active row

  • Thread starter Thread starter jcc31
  • Start date Start date
J

jcc31

Here is my code. I would like to know since every file has a different
amount of records, if there is a way process my code only to the last
active record?
In this case here I put 6500 records but I really do have that many
records.
And my record must start with the second record for processing.


Range("V2").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(C[-2],"" "",C[-10],""
"",C[-16])"
Selection.AutoFill Destination:=Range("V2:V*6500*"),
Type:=xlFillDefault
Range("V2:V65000").Select
Selection.Copy
Range("F2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Columns("T:Z").Select
Selection.ClearContents
 
Try this:

Dim cell As Range
Dim lastCell As Range
Dim theCells As Range

Set lastCell = Cells(6500, ActiveCell.Column).End(xlUp) 'find the last
active cell, change 6500 up or down to ensure coverage

Set theCells = Range(Cells(*X*, *ActiveCell.Column*), lastCell) 'X is
the value of starting row, ie *2* and ActiveCell.Column can be a
defined value, i.e *"V"*

For Each cell In theCells
If Not IsEmpty(cell) Then
'your code to do whatever
End If
Next

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top