VBA Question - Multiple Range Union Copy Pate - Excel 2010

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello All,

I have been working on project and have come to a halt because of code that isn't giving the needed result, I will explain below.

This code copies only the first range (Range1) properly from cell ("B14:H" & Lastrow) but leaves out range2?
Code:
Sub Copybook()
Dim range1 As Range, range2 As Range, multiplerange As Range
Set range1 = shtdata.Range("B14:H" & LastRow)
Set range2 = shtdata.Range("M14:N" & LastRow)
Set multiplerange = Application.Union(range1, range2)

  Sheets("Agreement").Activate
                 multiplerange.Select
                 Range(Selection, Selection.End(xlDown)).Select
                       Selection.Copy
       
 Sheets ("ODM").Range("C14").Select
                     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                       :=False, Transpose:=False
End Sub

And if I modify the formula to this below it copies both ranges as a union and paste them all across but the copy only goes half way down my data from ("B14:N32") when I really have data all the way down to ("B14:N86")?? I need to use the LastRow function because the rows won't always have the same amount of data.

Code:
Sub Copybook()
Dim range1 As Range, range2 As Range, multiplerange As Range
Set range1 = shtdata.Range("B14:H" & LastRow)
Set range2 = shtdata.Range("M14:N" & LastRow)
Set multiplerange = Application.Union(range1, range2)

  Sheets("Agreement").Activate
                 multiplerange.Select
                 'Range(Selection, Selection.End(xlDown)).Select
                       Selection.Copy
       
 Sheets ("ODM").Range("C14").Select
                     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                       :=False, Transpose:=False
End Sub

Any help with a recode or suggestions would be much appreciated.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Code:
Sub Macro1()'
' Macro1 Macro
'
Dim iRowBeg As Integer, iRowEnd As Integer, LR As Long
LR = Worksheets("Sheet1").UsedRange.SpecialCells(xlCellTypeLastCell).Row
    iRowBeg = Range("B14").Row
    iRowEnd = LR - iRowBeg + 1
    Intersect(Range("B1:H1,M1:N1").EntireColumn, Rows(iRowBeg).Resize(iRowEnd)).Select
    Selection.Copy
'
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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