Quick VBA Copy range with data in question

tezza

Active Member
Joined
Sep 10, 2006
Messages
375
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
  2. Web
Hi All,

I've done searches but can't quite find the right answer so I've come to you for help.

I'd like to vba code the following:

Count how many rows have data in it (B7:G7 Down with no empty rows but not all Columns filled hense the range)

Copy the data from M7:P7 down the number of rows counted above (This range has formulas in so using something like xldown doesn't appear to work).

Kind Regards
Terry
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
I'm not sure the works laptop will allow that.

Ultimately, what I'm after is to copy the data from M7:P7 down to the last row of data baring in mind it uses formulas to collect data from B7:G7 Down as staggered data.

Hope that explains it better.
 
Upvote 0
Is this what you are looking for?
VBA Code:
Sub MyCopy()

    Dim lr As Long
   
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
   
'   Copy down formula in M7:P7 to last row
    If lr > 7 Then Range("M7:P7").Copy Range("M8:M" & lr)
   
End Sub

If not, please at least post images (you can copy and paste images).
We won't be able to copy them, but at least then we can see how your data is structured and get a better idea of what you are after.
 
Upvote 0
Is this what you are looking for?
VBA Code:
Sub MyCopy()

    Dim lr As Long
 
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
 
'   Copy down formula in M7:P7 to last row
    If lr > 7 Then Range("M7:P7").Copy Range("M8:M" & lr)
 
End Sub

If not, please at least post images (you can copy and paste images).
We won't be able to copy them, but at least then we can see how your data is structured and get a better idea of what you are after.
HI,

It does something but doesn't save it to clipboard so that I can paste it somewhere else.

I can supply partial data - I wish to copy all the data in the yellow columns but not beyond as the destination has the same amount of rows.

Screenshot 2022-01-11 142824.png
 
Upvote 0
OK, I think I misunderstood your original query.

This will copy columns M:P from row 7 down to the last row, looking at column B, and wait for your paste.
VBA Code:
Sub MyCopy()

    Dim lr As Long
    
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Copy down formula in M7:P7 to last row
    Range("M7:P" & lr).Copy
    
End Sub
 
Upvote 0
OK, I think I misunderstood your original query.

This will copy columns M:P from row 7 down to the last row, looking at column B, and wait for your paste.
VBA Code:
Sub MyCopy()

    Dim lr As Long
   
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
   
'   Copy down formula in M7:P7 to last row
    Range("M7:P" & lr).Copy
   
End Sub
Hi,

I think it might fail as it can't rely on the data in Column B being in the last row, it would need to check the range (B:G) for the last row of data.

Regards
 
Upvote 0
OK, I think this should do that:
VBA Code:
Sub MyCopy()

    Dim lr As Long
    
'   Find last row in column B with data
    With Range("B7:G7").CurrentRegion
        lr = .Rows(.Rows.Count).Row
    End With
    
'   Copy down formula in M7:P7 to last row
    Range("M7:P" & lr).Copy
    
End Sub
 
Upvote 0
OK, I think this should do that:
VBA Code:
Sub MyCopy()

    Dim lr As Long
   
'   Find last row in column B with data
    With Range("B7:G7").CurrentRegion
        lr = .Rows(.Rows.Count).Row
    End With
   
'   Copy down formula in M7:P7 to last row
    Range("M7:P" & lr).Copy
   
End Sub
Almost, it copies to the bottom of col B:G not to the bottom row of data.
 
Upvote 0
Almost, it copies to the bottom of col B:G not to the bottom row of data.
I am not sure what you are talking about.

In your previous post, you said:
it would need to check the range (B:G) for the last row of data.
And that is exactly what it is doing.

If this is not what you want, then I don't think you are explaining yourself clearly.
Please walk us through an actual example, based on the data you posted, step-by-step.
Tell us EXACTLY what you want to happen, specifically (meaning, tell us EXACT range addresses).
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,273
Members
448,883
Latest member
fyfe54

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