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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,854
Messages
6,121,941
Members
449,056
Latest member
denissimo

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