FirstTimeExcel1
New Member
- Joined
- May 12, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
First of all, don't laugh at me lol, I am new to VBA so I could have done the below steps much more easily and less redundant but given my lack of experience I decided to brute force it with a lot of lines of code. The part of the code that I need to edit is the "RowNum = 5". I want to be able to manually select the cell and then have the macro run, where it automatically saves the Row Number (RowNum) of that cell as the variable below. Any thoughts?
VBA Code:
Sub HideColumns()
RowNum = 5
'Custom Brands
If Cells(RowNum, 56).Value <> "FALSE" Then
Cells(RowNum, 6).EntireColumn.Hidden = True
Cells(RowNum, 7).EntireColumn.Hidden = True
Cells(RowNum, 8).EntireColumn.Hidden = True
Cells(RowNum, 9).EntireColumn.Hidden = True
End If
If Cells(RowNum, 56).Value = 1 Then
Cells(RowNum, 6).EntireColumn.Hidden = False
Cells(RowNum, 7).EntireColumn.Hidden = False
Cells(RowNum, 8).EntireColumn.Hidden = False
Cells(RowNum, 9).EntireColumn.Hidden = False
End If
'DR
If Cells(RowNum, 57).Value <> "FALSE" Then
Cells(RowNum, 10).EntireColumn.Hidden = True
Cells(RowNum, 11).EntireColumn.Hidden = True
Cells(RowNum, 12).EntireColumn.Hidden = True
Cells(RowNum, 13).EntireColumn.Hidden = True
End If
If Cells(RowNum, 57).Value = 2 Then
Cells(RowNum, 10).EntireColumn.Hidden = False
Cells(RowNum, 11).EntireColumn.Hidden = False
Cells(RowNum, 12).EntireColumn.Hidden = False
Cells(RowNum, 13).EntireColumn.Hidden = False
End If
'ES
If Cells(RowNum, 58).Value <> "FALSE" Then
Cells(RowNum, 14).EntireColumn.Hidden = True
Cells(RowNum, 15).EntireColumn.Hidden = True
Cells(RowNum, 16).EntireColumn.Hidden = True
Cells(RowNum, 17).EntireColumn.Hidden = True
End If
If Cells(RowNum, 58).Value = 3 Then
Cells(RowNum, 14).EntireColumn.Hidden = False
Cells(RowNum, 15).EntireColumn.Hidden = False
Cells(RowNum, 16).EntireColumn.Hidden = False
Cells(RowNum, 17).EntireColumn.Hidden = False
End If
'HO
If Cells(RowNum, 59).Value <> "FALSE" Then
Cells(RowNum, 18).EntireColumn.Hidden = True
Cells(RowNum, 19).EntireColumn.Hidden = True
Cells(RowNum, 20).EntireColumn.Hidden = True
Cells(RowNum, 21).EntireColumn.Hidden = True
End If
If Cells(RowNum, 59).Value = 4 Then
Cells(RowNum, 18).EntireColumn.Hidden = False
Cells(RowNum, 19).EntireColumn.Hidden = False
Cells(RowNum, 20).EntireColumn.Hidden = False
Cells(RowNum, 21).EntireColumn.Hidden = False
End If
'HD
If Cells(RowNum, 60).Value <> "FALSE" Then
Cells(RowNum, 22).EntireColumn.Hidden = True
Cells(RowNum, 23).EntireColumn.Hidden = True
Cells(RowNum, 24).EntireColumn.Hidden = True
Cells(RowNum, 25).EntireColumn.Hidden = True
End If
If Cells(RowNum, 60).Value = 5 Then
Cells(RowNum, 22).EntireColumn.Hidden = False
Cells(RowNum, 23).EntireColumn.Hidden = False
Cells(RowNum, 24).EntireColumn.Hidden = False
Cells(RowNum, 25).EntireColumn.Hidden = False
End If
'LA
If Cells(RowNum, 61).Value <> "FALSE" Then
Cells(RowNum, 26).EntireColumn.Hidden = True
Cells(RowNum, 27).EntireColumn.Hidden = True
Cells(RowNum, 28).EntireColumn.Hidden = True
Cells(RowNum, 29).EntireColumn.Hidden = True
End If
If Cells(RowNum, 61).Value = 6 Then
Cells(RowNum, 26).EntireColumn.Hidden = False
Cells(RowNum, 27).EntireColumn.Hidden = False
Cells(RowNum, 28).EntireColumn.Hidden = False
Cells(RowNum, 29).EntireColumn.Hidden = False
End If
'LU
If Cells(RowNum, 62).Value <> "FALSE" Then
Cells(RowNum, 30).EntireColumn.Hidden = True
Cells(RowNum, 31).EntireColumn.Hidden = True
Cells(RowNum, 32).EntireColumn.Hidden = True
Cells(RowNum, 33).EntireColumn.Hidden = True
End If
If Cells(RowNum, 62).Value = 7 Then
Cells(RowNum, 30).EntireColumn.Hidden = False
Cells(RowNum, 31).EntireColumn.Hidden = False
Cells(RowNum, 32).EntireColumn.Hidden = False
Cells(RowNum, 33).EntireColumn.Hidden = False
End If
'P2
If Cells(RowNum, 63).Value <> "FALSE" Then
Cells(RowNum, 34).EntireColumn.Hidden = True
Cells(RowNum, 35).EntireColumn.Hidden = True
Cells(RowNum, 36).EntireColumn.Hidden = True
Cells(RowNum, 37).EntireColumn.Hidden = True
End If
If Cells(RowNum, 63).Value = 8 Then
Cells(RowNum, 34).EntireColumn.Hidden = False
Cells(RowNum, 35).EntireColumn.Hidden = False
Cells(RowNum, 36).EntireColumn.Hidden = False
Cells(RowNum, 37).EntireColumn.Hidden = False
End If
'PD
If Cells(RowNum, 64).Value <> "FALSE" Then
Cells(RowNum, 38).EntireColumn.Hidden = True
Cells(RowNum, 39).EntireColumn.Hidden = True
Cells(RowNum, 40).EntireColumn.Hidden = True
Cells(RowNum, 41).EntireColumn.Hidden = True
End If
If Cells(RowNum, 64).Value = 9 Then
Cells(RowNum, 38).EntireColumn.Hidden = False
Cells(RowNum, 39).EntireColumn.Hidden = False
Cells(RowNum, 40).EntireColumn.Hidden = False
Cells(RowNum, 41).EntireColumn.Hidden = False
End If
'RO
If Cells(RowNum, 65).Value <> "FALSE" Then
Cells(RowNum, 42).EntireColumn.Hidden = True
Cells(RowNum, 43).EntireColumn.Hidden = True
Cells(RowNum, 44).EntireColumn.Hidden = True
Cells(RowNum, 45).EntireColumn.Hidden = True
End If
If Cells(RowNum, 65).Value = 10 Then
Cells(RowNum, 42).EntireColumn.Hidden = False
Cells(RowNum, 43).EntireColumn.Hidden = False
Cells(RowNum, 44).EntireColumn.Hidden = False
Cells(RowNum, 45).EntireColumn.Hidden = False
End If
'SS
If Cells(RowNum, 66).Value <> "FALSE" Then
Cells(RowNum, 46).EntireColumn.Hidden = True
Cells(RowNum, 47).EntireColumn.Hidden = True
Cells(RowNum, 48).EntireColumn.Hidden = True
Cells(RowNum, 49).EntireColumn.Hidden = True
End If
If Cells(RowNum, 66).Value = 11 Then
Cells(RowNum, 46).EntireColumn.Hidden = False
Cells(RowNum, 47).EntireColumn.Hidden = False
Cells(RowNum, 48).EntireColumn.Hidden = False
Cells(RowNum, 49).EntireColumn.Hidden = False
End If
'SP
If Cells(RowNum, 67).Value <> "FALSE" Then
Cells(RowNum, 50).EntireColumn.Hidden = True
Cells(RowNum, 51).EntireColumn.Hidden = True
Cells(RowNum, 52).EntireColumn.Hidden = True
Cells(RowNum, 53).EntireColumn.Hidden = True
End If
If Cells(RowNum, 67).Value = 12 Then
Cells(RowNum, 50).EntireColumn.Hidden = False
Cells(RowNum, 51).EntireColumn.Hidden = False
Cells(RowNum, 52).EntireColumn.Hidden = False
Cells(RowNum, 53).EntireColumn.Hidden = False
End If
End Sub