Running Two Macros

PHIL.Pearce84

Board Regular
Joined
May 16, 2011
Messages
152
Office Version
  1. 365
Platform
  1. Windows
My spreadsheet wont let me run two macros that are entered in the VBA can anyone help?

This is what I have:

Sub HideRows()
On Error Resume Next
With Range("H1:H1100")
.EntireRow.Hidden = False
For i = 1 To .Rows.Count
If WorksheetFunction.Sum(.Rows(i)) = 1 Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
End With

End Sub
Option Explicit
Private Sub CommandButton1_Click()
Dim wsEach As Worksheet
Dim blnFound As Boolean
Dim strSheet As String
On Error GoTo ErrHnd
'set Found flag to 'not found'
blnFound = False
'get sheet name from cell C4
strSheet = ActiveSheet.Range("C4").Text
'test that E22 contains a valid sheet name
'go through each worksheet in this workbook
For Each wsEach In ActiveWorkbook.Worksheets()
'if found, flag as 'found'
If strSheet = wsEach.Name Then blnFound = True
Next wsEach
If blnFound = False Or strSheet = ActiveSheet.Name Then
'not found or it is 'this' worksheet - so show a message
If strSheet = "" Then
MsgBox "Select Scheme name in cell C4 before proceeding"
ElseIf strSheet = ActiveSheet.Name Then
MsgBox "Cannot select this worksheet as sheet to jump to"
Else
MsgBox "Select a valid worksheet name in cell C4"
End If
Exit Sub
End If
'activate the worksheet selected in cell C4
Worksheets(strSheet).Activate
'activate a specific cell on that worksheet
Worksheets(strSheet).Range("A1").Activate
Exit Sub
'error handler
ErrHnd:
Err.Clear
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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