# Macro to copy a variable range

#### cmrluvitlevit

##### New Member
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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

#### VoG

##### Legend
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
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
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``````

That works!

Thanks VoG!

-Chris

1,106,998
Messages
5,514,710
Members
409,014
Latest member
evenyougreg