neilcsmith1984
New Member
- Joined
- May 25, 2020
- Messages
- 14
- Office Version
- 2013
- Platform
- Windows
Hi,
I am very new to VBA and have managed to find and adapt the 2 below codes to work on separate sheets.
I am not sure if this is possible, however, I would like to have both codes working on sheet 1 together.
Code 1: (currently in sheet 1)
Sub SetVisible()
Dim s1 As Shape, s2 As Shape
Set s1 = Me.Shapes("Rectangle 1")
Set s2 = Me.Shapes("Rectangle 2")
Select Case UCase(Range("A1").Value)
Case "2015"
s1.Visible = msoTrue
s2.Visible = msoFalse
Case "2016"
s1.Visible = msoFalse
s2.Visible = msoTrue
Case "ALL"
s1.Visible = msoTrue
s2.Visible = msoTrue
Case Else
s1.Visible = msoFalse
s2.Visible = msoFalse
End Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then SetVisible
End Sub
Code 2: (currently in Sheet 2
Private Sub Worksheet_Calculate()
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
On Error Resume Next
For Each c In Range("E1:E" & LastRow)
If c.Value = 1 Then
c.EntireRow.Hidden = True
ElseIf c.Value = 2 Then
c.EntireRow.Hidden = False
End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub
If anyone can help me get these 2 codes working on one sheet, I would be so grateful....
Thanks
I am very new to VBA and have managed to find and adapt the 2 below codes to work on separate sheets.
I am not sure if this is possible, however, I would like to have both codes working on sheet 1 together.
Code 1: (currently in sheet 1)
Sub SetVisible()
Dim s1 As Shape, s2 As Shape
Set s1 = Me.Shapes("Rectangle 1")
Set s2 = Me.Shapes("Rectangle 2")
Select Case UCase(Range("A1").Value)
Case "2015"
s1.Visible = msoTrue
s2.Visible = msoFalse
Case "2016"
s1.Visible = msoFalse
s2.Visible = msoTrue
Case "ALL"
s1.Visible = msoTrue
s2.Visible = msoTrue
Case Else
s1.Visible = msoFalse
s2.Visible = msoFalse
End Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then SetVisible
End Sub
Code 2: (currently in Sheet 2
Private Sub Worksheet_Calculate()
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
On Error Resume Next
For Each c In Range("E1:E" & LastRow)
If c.Value = 1 Then
c.EntireRow.Hidden = True
ElseIf c.Value = 2 Then
c.EntireRow.Hidden = False
End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub
If anyone can help me get these 2 codes working on one sheet, I would be so grateful....
Thanks