Merge two pieces of code

Rubber Beaked Woodpecker

Board Regular
Joined
Aug 30, 2015
Messages
205
Office Version
  1. 2021
Currently I use the following code that works very well but I would like to tidy it a little so that instead of calling Macro1 the code in Macro1 will be incorporated in to the original code.

However no matter what I try I get a 400 error!

Any help please :)

RBW

VBA Code:
Sub Report()
  
Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long

Set source = Sheets("Sheet1")
Set destination = Sheets("Sheet8")

source.Range("BG4:BG230").Copy

emptyColumn = destination.Cells(2, destination.Columns.Count).End(xlToLeft).Column

If IsEmpty(destination.Range("A2")) Then
    destination.Cells(1, 1).PasteSpecial Transpose:=True
      
Else
    emptyColumn = emptyColumn + 1
    destination.Cells(2, emptyColumn).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
       
         destination.Cells(2, emptyColumn).PasteSpecial Paste:=xlPasteFormats
            
Sheets("Sheet8").Select
                 
         Call Macro1
End If
  
End Sub

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

'

    Range( _
        "A1:C246,D235:X246,D209:X220,D175:X194,D142:X153,D112:X127,D83:X94"). _
        Select
    Range("D83").Activate
   
    Sheets("Sheet8").Select
         ActiveSheet.Calculate
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Screwed my head on I have this working now :)

VBA Code:
Sub Report()
  
Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long

Set source = Sheets("Sheet1")
Set destination = Sheets("Sheet8")

source.Range("BG4:BG230").Copy

emptyColumn = destination.Cells(2, destination.Columns.Count).End(xlToLeft).Column

If IsEmpty(destination.Range("A2")) Then
    destination.Cells(1, 1).PasteSpecial Transpose:=True
      
Else
    emptyColumn = emptyColumn + 1
    destination.Cells(2, emptyColumn).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
       
         destination.Cells(2, emptyColumn).PasteSpecial Paste:=xlPasteFormats
            
       
      destination.Range("A1:C246,D235:X246,D209:X220,D175:X194,D142:X153,D112:X127,D83:X94"). _
        Select
       
    Sheets("Sheet8").Select
         ActiveSheet.Calculate
End If
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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