Macro to number down rows.

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I need another macro but recording it wont work as I have a different amount of rows in each file I will use it on. Starting in A2 I need it to number down 1 to whatever row is the last i.e 1 to 7386 rows when there is that amount. Its another part I can add to my macro. Thanks.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try:

Code:
Dim LR as Long
Dim i as Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 to LR
    'Your code here
Next i
 
Upvote 0
I need it at the very end of my code but it comes up with a Compile error:
Duplicate declaration in current scope.
 
Upvote 0
Are you just looking to number the rows?

This numbers down as far as column B.

Code:
Sub Macro1()
    Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row).Formula = "=ROW(A1)"
End Sub
 
Upvote 0
I think I need these 2 codes sort of made as 1!!

Code:
Dim LR As Long, i As Long
LR = Range("G" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
If IsError(Range("G" & i)) Then Rows(i).Delete
Next i
Dim LR As Long
Dim i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
'Your code here
Next i
 
Upvote 0
Not entirely clear what you want here.

Do you want to delete all #N/A from column G and then number the rows left starting in A2?

Code:
Sub FilterDelete()
    With Range("G1", Range("G" & Rows.Count).End(xlUp))
        .AutoFilter field:=1, Criteria1:="#N/A"
        .Offset(1).EntireRow.Delete
        .AutoFilter
    End With
    Range("A2:A" & Range("G" & Rows.Count).End(xlUp).Row).Formula = "=ROW(A1)"
End Sub
 
Upvote 0
I added your previous bit of code to mine and it works fine, thanks.
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,223
Members
452,896
Latest member
IGT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top