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.
 

Some videos you may like

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
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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

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

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top