Amending Recorded Macro

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
I have recorded the macro below that autofills and for use on future files. The problem is that the amount of rows will increase each time but if I use the recorded macro it will not fill all rows only to B16342. What can I change so it autofills all the rows in each file going forwards?

What it needs to do is put the number of rows in column A in this case 1 to 16342 and put number 1 in each cell in column B, both starting in row 2. Thanks.

Code:
Range("A2").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("A3").Select
    ActiveCell.FormulaR1C1 = "2"
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("B3").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("A2:B3").Select
    Selection.AutoFill Destination:=Range("A2:B16342"), Type:=xlFillDefault
    Range("A2:B16342").Select
    Range("A1").Select
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How would you determine how many rows are needed?
 
Upvote 0
I don't know, the number will increase a different amount each future file.
 
Upvote 0
If you don't know how to determine the number of rows need, how do you expect a macro to do it?
 
Upvote 0
Sorry I understand what you mean now. All other columns from C onwards will have data in, A and B will be empty so I guess the macro will have to count the amount of used rows in column C?
 
Upvote 0
Ok, how about
VBA Code:
Sub Dazzawm()
   With Range("A2:A" & Range("C" & Rows.Count).End(xlUp).Row)
      .Formula = "=row(a1)"
      .Value = .Value
      .Offset(, 1).Value = 1
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,486
Messages
6,113,932
Members
448,533
Latest member
thietbibeboiwasaco

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