VBA Loop Until Help

Samantha Roberts

New Member
Joined
Mar 18, 2010
Messages
6
I have data on one spreadsheet which gets added to each month 'Raw Data'.

On a different tab within the same workbook 'Formatted Data' - i have formulae in row 2, from column A-O. Note: the formulae is different in each cell. It pulls different data from the 'Raw Data' based on criteria in column A of 'Raw Data'.

At the moment - every time 'Raw Data' is added to, i have to go to 'Formatted Data' and copy the formulae down until it picks up the last row of 'Raw Data'.

I have writen the following to autofill rather than having to do it manually but id like to not have the range "2:2500" defined.

Instead, for it to autofill until the result is 0 (i.e. it's picked up all the rows from 'Raw Data'.


Sub copy()

With Worksheets("Formatted Data")


Range("2:2").AutoFill .Range("2:2500")

End With


End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try

Code:
Sub copy()
Dim LR As Long
LR = Sheets("Raw Data").Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row

With Worksheets("Formatted Data")


    .Range("2:2").AutoFill .Range("2:" & LR)

End With


End Sub
 
Upvote 0
One way:

Code:
Sub copy()
Dim lLR As Long
With Worksheets("Raw Data")
    lLR = .Range("A" & .Rows.Count).End(xlUp).Row
End With
With Worksheets("Formatted Data")
    .Range("2:2").AutoFill .Range("2:" & lLR)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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