PHIL.Pearce84
Board Regular
- Joined
- May 16, 2011
- Messages
- 152
- Office Version
- 365
- Platform
- 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
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