MartinSpellacy

New Member
Joined
Jun 6, 2018
Messages
4
Hi,

I have the below table which has 5 colums in it. The data in columns B to D is already populated for me however the only data in column A is found in Cell A2. I have created a macro to auto fill column A ( please see below). In my example I have 236 rows to autofil.

My problem is this.... my row range is dynamic and I may have less or more rows. How to I edit the macro so that it autofills to the potential last row?

Thanks in advnace



Depot WIP DeptStatusDate In
Aberdeen22717 W128/03/2018
Aberdeen24105 W127/04/2018
Aberdeen24048 W105/04/2018
Aberdeen24330 W105/04/2018

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>



Sheets("Ab").Select
Range("A2").Select
Selection.autofill Destination:=Range("A2:A236")
Range("A2:A236").Select
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Welcome to the Board!

We can use column B to dynamically find the last row, and then autofill, i.e.
Code:
Dim lr as Long
lr = Cells(Rows.Count,"B").End(xlUp).Row
[COLOR=#333333]Range("A2").A[/COLOR][COLOR=#333333]utofill Destination:=Range("A2:A" & lr)[/COLOR]
 
Upvote 0
in a helper cell count the non blank rows, say it is in AA1 then loop the macro from 2 to cells(1,27)
 
Upvote 0
What I gave you is all you need.
Replace what you have now (and posted originally) with that (within your procedure), i.e.
Code:
Sub MyAutoFill()

    Dim lr As Long
    
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    Range("A2").AutoFill Destination:=Range("A2:A" & lr)

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,473
Messages
6,130,838
Members
449,597
Latest member
buikhanhsang

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