Macro to copy a variable range

cmrluvitlevit

New Member
Joined
Oct 9, 2007
Messages
41
I have a table B7:R100. This table is not always filled out to row 100. I need to write a macro that will copy C7:R100 if there is a value in column B. Column B will always have a number until the end of the list.

For example today the list may go from B7:R50, but tomorrow the list is B7:R57.

Thanks for the help. I am not a VBA guru and can not figure how to write the variable.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try like this

Code:
Sub CopyBR()
Dim LR As Long
With Sheets("Sheet1")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    .Range("B7:R" & LR).Copy Destination:=Sheets("Sheet2").Range("A1")
End With
End Sub
 

cmrluvitlevit

New Member
Joined
Oct 9, 2007
Messages
41
VoG,

Since there is an equation in each cell in column B the macro copies the entire table B7:R100. The equation in column B cells is an if statement that put 1,2,3,4 respectively if there is data in the following row cells.

What changes could be made to stop the 'copy' function when the cell value for B = "".

Thanks
Chris
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub CopyBR()
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    i = LR
    Do Until .Range("B" & i).Value <> ""
        i = i - 1
    Loop
    .Range("B7:R" & i).Copy Destination:=Sheets("Sheet2").Range("A1")
End With
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,701
Messages
5,833,215
Members
430,197
Latest member
edeibold

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
Top