Set Copy range to depth on on one column of data, then copy extended range width

Kerry Newman

New Member
Joined
Feb 23, 2018
Messages
19
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
In the attached picture the data in G11:J25 will change in rows deep when a slicer changes the data selection. Also the data in columns K,L,M which are VLOOKUPs, will change too.
I want to copy and paste only G11 to M25 (in this case) to cell T11. But my macro is copying G11:M39 (or further actually M20000).
When I select another option in the slicer, the list may be G11: M20. or maybe G11:M35....... I only want ROWS with data in column G,H,I or J but through column M my code is not doing this.....

Sub Macro3()
'
' Macro3 Macro
'

'
Range("H11:M20000" & Cells(Rows.Count, "C").End(xlUp).Row).Select
Selection.Copy
Range("T11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("T8").Select
End Sub

Any suggestions?
 

Attachments

  • Excel.PNG
    Excel.PNG
    172.5 KB · Views: 4

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try removing the 20000 (the Select and Selection can also go)

VBA Code:
Sub Macro3()
'
' Macro3 Macro
'

'
Range("H11:M" & Cells(Rows.Count, "C").End(xlUp).Row).Copy
Range("T11").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("T8").Select
 
Upvote 0
Would this also work for you?

VBA Code:
Sub Macro3_v2()
  Range("T11:Z" & Range("G" & Rows.Count).End(xlUp).Row).Value = Range("G11:M" & Range("G" & Rows.Count).End(xlUp).Row).Value
End Sub

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Solution
Would this also work for you?

VBA Code:
Sub Macro3_v2()
  Range("T11:Z" & Range("G" & Rows.Count).End(xlUp).Row).Value = Range("G11:M" & Range("G" & Rows.Count).End(xlUp).Row).Value
End Sub

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Thanks, that worked perfect
 
Upvote 0
Try removing the 20000 (the Select and Selection can also go)

VBA Code:
Sub Macro3()
'
' Macro3 Macro
'

'
Range("H11:M" & Cells(Rows.Count, "C").End(xlUp).Row).Copy
Range("T11").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("T8").Select
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,559
Messages
6,120,194
Members
448,951
Latest member
jennlynn

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