Macros work separately but not together

svendiamond

Well-known Member
Joined
Jun 13, 2014
Messages
1,504
Office Version
  1. 365
Platform
  1. Windows
The point of this workbook I'm creating is to make an ugly system-generated report look nice. The user pastes the report onto the first page, then clicks a macro button that does everything. "Everything" includes deleting some columns to make it line up correctly, then copying and pasting the values to another sheet, yada yada yada.

I just need one more thing which is to Fill (up, not down) columns A, B, and C. I have a 2nd macro button on the final page that does this and works just fine. However, I would rather the user only have to click one button. So, I copied the code from this second button and added it to the end of my first button's code. But, now when I click the button, it only seems to run the first code. I don't get an error or anything... but the second code doesn't happen... it doesn't "fill up" those three columns.


Rich (BB code):
Private Sub CommandButton1_Click()
'
' ADJUST_REPORT Macro
'
' This first part formats the first sheet to align correctly

    Range("C5:C46").Select
    Selection.Delete Shift:=xlToLeft
    Range("G5:G46").Select
    Selection.Delete Shift:=xlToLeft
    Range("I5:I46").Select
    Selection.Delete Shift:=xlToLeft
    Range("O5:O46").Select
    Selection.Delete Shift:=xlToLeft
    
' So, now the first sheet is formatted and this part copies it and pastes it onto the next sheet:
    
    Cells.Select
    Selection.Copy
    Worksheets("ADJUSTED").Visible = True
    Sheets("ADJUSTED").Select
    Sheets("ADJUSTED").Range("A1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Worksheets("ADJUSTED").Visible = False
    
' Now this will copy the "COPY THIS" sheet and paste it onto the "FINAL" sheet
    
    Worksheets("COPY THIS").Visible = True
    Sheets("COPY THIS").Select
    ActiveSheet.Cells.Select
    Selection.Copy
    Sheets("FINAL").Select
    Sheets("FINAL").Range("A1").PasteSpecial Paste:=xlValues
    Worksheets("COPY THIS").Visible = False
    Application.CutCopyMode = False
    
' Now we will fill up all the values in columns A/B/C (THIS IS THE PART THAT ISN'T WORKING):
    
    Sheets("FINAL").Select
    Lastrow = Range("A65000").End(xlUp).Row
    For i = Lastrow To 2 Step -1
    If Not IsError(Range("A" & i)) Then
        RecordA = Range("A" & i)
        RecordB = Range("B" & i)
        RecordC = Range("C" & i)
    Else
        Range("A" & i) = RecordA
        Range("B" & i) = RecordB
        Range("C" & i) = RecordC
    End If
    Next i
    
End Sub

I had that last part on the separate button and it worked just fine. But now it just doesn't do anything. Like I said, I don't get an error message. It just doesn't do what it's supposed to do (fill UP columns A/B/C). Thanks for any help you can provide.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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