Copy multiple ranges

bujaman

Board Regular
Joined
Apr 2, 2009
Messages
56
I am attempting to copy multiple ranges of cells from one worksheet and paste them into another to the next open row. What the code does is look through a selected workbook for worksheets that begin with certain characters (see the "CASE" below), and then copies the specified ranges to the next open row. I am having some problems with the
Code:
sh.Range("A8:BH48,A55:BH104,A113:BH130,A133:BH152,A158:BH160,A164:BH166,A172:BH174").Select
part of the code. Any help would be awesome! Thanks!

Code:
Private Sub InstallProducts_Click()


Application.ScreenUpdating = False
If FilePath.Value = "" Then
MsgBox "Please Select a File to Install", vbOKOnly, "Blind Bid Pro"
Exit Sub

Else
Unload Me

Dim wkbSource As Workbook
Dim WorkbookName As String
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim LastRow As Long
Dim wbsnum As Range

Set DestSh = Worksheets("Cost Summary")


WorkbookName = ThisWorkbook.Name

    Set wkbSource = Workbooks.Open(FilePath.Value)


DestSh.Activate
For Each sh In wkbSource.Worksheets



    Select Case Left(sh.Name, 4)

        Case "C.01" ', "D.01", "D.02", "D.03", "E.01", "E.02", "E.03", "E.04", "E.05", "E.06", "E.07", "F.01", "F.04", "F.05", "F.06", "G.01", "G.02", "H.01", "H.02", "I.01", "Z.01", "Z.02", "Z.03", "Z.04", "F.02", "F.03", "Y.01", "Y.02"
    '...add all WBS numbers here, there will be many!
            LastRow = FindLastRow(DestSh, "B")

            sh.Range("A8:BH48,A55:BH104,A113:BH130,A133:BH152,A158:BH160,A164:BH166,A172:BH174").Select
            Selection.Copy
            DestSh.Cells(LastRow + 2, 2).Select

            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

            ActiveCell.Offset(0, -1) = Left(sh.Range("A3").Text, 18) 'Left(sh.Name, 4)
            ActiveCell.Offset(0, -1).Copy
            Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(41, -1)).Select
            ActiveSheet.Paste


    End Select

Next sh


wkbSource.Activate

ActiveWorkbook.Close SaveChanges:=False


ActiveWorkbook.Save
Range("A1").Select

End If
    Range("A4:C65536").Select
    Selection.AutoFilter
    Range("A1").Select
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You need to loop through each area in the range to be copied.

For example :-

Code:
Dim area as Range
For Each area in Selection.Areas
    area.Copy
    'your paste code,etc.
Next
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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