Jeremy4110
Board Regular
- Joined
- Sep 26, 2015
- Messages
- 70
Hi,
I'm trying to copy multiple ranges using the cell properties. I have tried a bunch of alternate combinations of the second macro below but have been unable to get any to work.
The first macro was a recording and it works, but it will always be the same four ranges, I wanted to try and use the “Cell Property” so that I could use a variable location like “MaxRow = ActiveSheet.UsedRange.Rows.Count” because it allows changes.
Any help is greatly appreciated.
Thanks,
Jeremy
This is the recorded macro.
This the macro that I have not been able to get to work
I'm trying to copy multiple ranges using the cell properties. I have tried a bunch of alternate combinations of the second macro below but have been unable to get any to work.
The first macro was a recording and it works, but it will always be the same four ranges, I wanted to try and use the “Cell Property” so that I could use a variable location like “MaxRow = ActiveSheet.UsedRange.Rows.Count” because it allows changes.
Any help is greatly appreciated.
Thanks,
Jeremy
This is the recorded macro.
Code:
Sub Macro1()
Range("A1:A2,B1:K2,A14:A19,B14:K19").Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Range("A1").Select
ActiveSheet.Paste
Cells.Select
Cells.EntireColumn.AutoFit
Application.CutCopyMode = False
Range("A1").Select
End Sub
This the macro that I have not been able to get to work
Code:
Sub TESTSample()
Dim rng1 As Range, rng2 As Range
Set rng1 = Range(Cells(1, 1), Cells(2, 1)) '("A1:A2")
Set rng2 = Range(Cells(1, 2), Cells(2, 11)) '("B1:K2")
rng1.Select 'This works
rng2.Select 'This works
'Range("A1:A2,B1:K2,A14:A19,B14:K19").Select 'This is the ultimate goal and it works but I need to use variable ranges rather than fixed ranges
Range(Cells(rng1), Cells(rng2)).Select 'This is an example that does NOT work
End Sub