how to code for different letters

TiggerToo

Board Regular
Joined
Feb 26, 2002
Messages
158
The below formula works good for when I put any letter in G13, but what I want to accomplish is to put a specific letter in G13
The Example formula is what I am trying to accomplish with a specific letter to work, letter A to hide rows 119 to 123, B to hide 402 to 415, C to hide rows 119 to 158 and D and M to not hide any rows just hide sheet (model) etc.
I do not know how to make the code to work for each different letter. can it be shorten. Please help!!

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.DisplayAlerts = False
If Target.Address = Range("G13").Address Then
If Target.Value = "" Then
Worksheets("Model").Visible = False
Else
Worksheets("Model").Visible = True
Worksheets("Aircraft").Visible = False
End If
End If
ActiveWorkbook.Saved = True
Application.DisplayAlerts = True
End Sub

Example:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.DisplayAlerts = False
If Target.Address = Range("G13").Address Then
If Target.Value = D or M
Worksheets("MSG").Visible = False
Else
Worksheets("MSG").Visible = True
Worksheets("Model").Visible = False
End If
End If
If Target.Address = Range("G13").Address = A Then
If Target.Value = A Then
Worksheets("MSG").Visible = False
Worksheets("incoming").Range("119:123").EntireRow.Hidden = True
Else
Worksheets("incoming").Range("119:123").EntireRow.Hidden = False
Worksheets("MSG").Visible = True
Worksheets("Model").Visible = False
End If
End If
If Target.Address = Range("G13").Address = B Then
If Target.Value = B Then
Worksheets("MSG").Visible = False
Worksheets("incoming").Range("633:706").EntireRow.Hidden = True
Else
Worksheets("incoming").Range("633:706").EntireRow.Hidden = False
Worksheets("MSG").Visible = True
Worksheets("Model").Visible = False
End If
End If
If Target.Address = Range("G13").Address = C Then
If Target.Value = C Then
Worksheets("MSG").Visible = False
Worksheets("incoming").Range("119:158,633:706").EntireRow.Hidden = True
Else
Worksheets("incoming").Range("119:158,633:706").EntireRow.Hidden = False
Worksheets("MSG").Visible = True
Worksheets("Model").Visible = False
End If
End If
ActiveWorkbook.Saved = True
Application.DisplayAlerts = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I can't tell exactly what you're trying to do, but this may give you some ideas:

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Address = "$G$13" Then
        Select Case UCase(Target.Value)
            Case "D", "M"
                Worksheets("MSG").Visible = xlSheetHidden
            Case "A"
                Worksheets("MSG").Visible = xlSheetHidden
                Worksheets("incoming").Range("119:123").EntireRow.Hidden = True
            Case "B"
                Worksheets("MSG").Visible = xlSheetHidden
                Worksheets("incoming").Range("633:706").EntireRow.Hidden = True
            Case "C"
                Worksheets("MSG").Visible = xlSheetHidden
                Worksheets("incoming").Range("119:158,633:706").EntireRow.Hidden = True
            Case Else
                ' none of the above; what do you want to do?
        End Select
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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