Stop macro at empty cell

swarren

New Member
Joined
Jul 16, 2014
Messages
9
I need help with a macro in vba to copy a cell range from one sheet into another but I want it to stop when it comes to an empty cell. 1st sheet I copy b2:b? and d2:I? and paste into 2nd sheet.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Something like this?

Code:
Sub Macro1()

Dim sh As Worksheet
Set sh = Sheets("Sheet1")

If sh.Range("B3").Value <> "" Then

    sh.Range(sh.Range("B2"), sh.Range("B2").End(xlDown)).Copy _
    Destination:=Worksheets("Sheet2").Range("A1")
    
    sh.Range(sh.Range("D2:I2"), sh.Range("D2:I2").End(xlDown)).Copy _
    Destination:=Worksheets("Sheet2").Range("B1")
    
Else
    sh.Range("B2").Copy Destination:=Worksheets("Sheet2").Range("A1")
    sh.Range("D2:I2").Copy Destination:=Worksheets("Sheet2").Range("B1")
    
End If

End Sub
 
Upvote 0
I actually have 4 worksheets. The first 1 one is input, 2nd document, 3rd transaction and upload. Yes, there are different amounts each time I copy my data from the input sheet. There is data in columns a thru m but I only need to copy certain columns from each sheet The amount of data could be from a2:a200 or a2:a30. I need the macro to stop at the end of the last column when it comes to a blank cell. I am not sure how to write it. I am new at this and trying to learn.

Thanks
 
Upvote 0
In that case try eg:

Code:
With Worksheets("Sheet1")
    .Range("B2:B" & .Range("B" & .Rows.Count).End(xlUp).Row).Copy Worksheets("Sheet2").Range("B2")
End With
 
Upvote 0
Would I put that for each sheet or would that apply to all of them? What would go after End With? Sorry for so many questions but I have my macro recorded and I am trying to add this in.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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