Base Excel Sheet with Macro Buttons to Run Code on other Sheets

Kdevisser25

New Member
Joined
Sep 13, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I have a base sheet where I have notes to a user and instructions that contain macros. I would like to user to import a sheet that is downloaded off a database into the workbook as Sheet2 and then go back to the "Base Sheet" (where the macro buttons are located) and select the buttons to appropriately scale and format the data. I am no VSB whiz and I am having trouble getting the macro on the base sheet to run on Sheet2 vice the Base sheet.

Below is the code I am trying to run which works well on the current sheet, but not on a different sheet in the workbook. Even when I try to call out Sheet2 instead of ActiveSheet I still can't get it to work right.

Sub InsertPageBreaks()
'updateby Extendoffice
Dim I As Long, J As Long
J = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For I = J To 3 Step -1
If Range("A" & I).Value <> Range("A" & I - 1).Value Then
ActiveSheet.HPageBreaks.Add Before:=Range("A" & I)
End If
Next I
End Sub


Any thoughts? Any help would be greatly appreciated.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
'Cause you forgot some worksheet references !​
VBA Code:
Sub Demo1()
        Dim R As Long
    With Sheet2
        For R = .Cells(.Rows.Count, 1).End(xlUp).Row To 3 Step -1
            If .Cells(R, 1).Value2 <> .Cells(R - 1, 1).Value2 Then .HPageBreaks.Add .Cells(R, 1)
        Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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