Hi! I'm new to VBA and trying to figure out how to simplify the codes I have.
Below is one I have where user will select a value from cover sheet (1,2,3,etc.) from cell [no_pin] and the number selected will determine the sheets that will be visible ("Pin-1","Pin-2", etc.).
The title of the worksheet is essentially "Pin-(cellvalue)".
Sub Macro2(ByVal Target As Range)
Dim pn1 As Worksheet
Set pn1 = Sheets("Pin-1")
Dim pn2 As Worksheet
Set pn2 = Sheets("Pin-2")
Dim pn3 As Worksheet
Set pn3 = Sheets("Pin-3")
If [no_pin] = "0" Then
pn1.Visible = xlSheetHidden
pn2.Visible = xlSheetHidden
pn3.Visible = xlSheetHidden
Else
pn1.Visible = xlSheetVisible
pn2.Visible = xlSheetVisible
pn3.Visible = xlSheetVisible
End If
If [no_axle] = "1" Then
ax2.Visible = xlSheetHidden
ax3.Visible = xlSheetHidden
End If
If [no_axle] = "2" Then
ax3.Visible = xlSheetHidden
End If
End Sub
Thanks in advance!
Below is one I have where user will select a value from cover sheet (1,2,3,etc.) from cell [no_pin] and the number selected will determine the sheets that will be visible ("Pin-1","Pin-2", etc.).
The title of the worksheet is essentially "Pin-(cellvalue)".
Sub Macro2(ByVal Target As Range)
Dim pn1 As Worksheet
Set pn1 = Sheets("Pin-1")
Dim pn2 As Worksheet
Set pn2 = Sheets("Pin-2")
Dim pn3 As Worksheet
Set pn3 = Sheets("Pin-3")
If [no_pin] = "0" Then
pn1.Visible = xlSheetHidden
pn2.Visible = xlSheetHidden
pn3.Visible = xlSheetHidden
Else
pn1.Visible = xlSheetVisible
pn2.Visible = xlSheetVisible
pn3.Visible = xlSheetVisible
End If
If [no_axle] = "1" Then
ax2.Visible = xlSheetHidden
ax3.Visible = xlSheetHidden
End If
If [no_axle] = "2" Then
ax3.Visible = xlSheetHidden
End If
End Sub
Thanks in advance!