With the help of GPT (and you guys), I wrote some VBA code that will automatically hide rows in another sheet depending on whether the answer is "Yes" or "No" in my current sheet.
My "Input Fields" tab has a list of parts. I can either select "Yes" or "No" for each part.
The "Commercial Invoice" sheet lists every single part by default, but if I select "No" to one of the parts in my "Input Fields" tab, I want the row in my "Commercial Invoice" tab to be completely hidden, automatically.
The macro for the HideRows() sub works perfectly fine when I run it manually, but the Module code does not, since the rows aren't being hidden automatically. The rows will only hide if I run the macro, but I want it to happen seamlessly. Here's the module code I am using:
Sub HideRows()
Dim wsInput As Worksheet
Dim wsInvoice As Worksheet
Dim toolkitToggle As Range, cageToggle As Range, boxToggle As Range
Dim toolkitRow As Range, cageRow As Range, boxRow As Range
' Set worksheets
Set wsInput = ThisWorkbook.Worksheets("Input Fields")
Set wsInvoice = ThisWorkbook.Worksheets("Commercial Invoice")
' Set toggle cells (Input Fields)
Set toolkitToggle = wsInput.Range("Toolkit_Toggle")
Set cageToggle = wsInput.Range("Cage_Toggle")
Set boxToggle = wsInput.Range("Box_Toggle")
' Set rows to hide/unhide (Commercial Invoice)
Set toolkitRow = wsInvoice.Range("Toolkit_Row")
Set cageRow = wsInvoice.Range("Cage_Row")
Set boxRow = wsInvoice.Range("Box_Row")
' Debugging: Display toggle values
Debug.Print "Toolkit_Toggle: " & toolkitToggle.Value
Debug.Print "Cage_Toggle: " & cageToggle.Value
Debug.Print "Box_Toggle: " & boxToggle.Value
' Toolkit Row Logic
If UCase(toolkitToggle.Value) = "YES" Then
toolkitRow.EntireRow.Hidden = False
Else
toolkitRow.EntireRow.Hidden = True
End If
' Cage Row Logic
If UCase(cageToggle.Value) = "YES" Then
cageRow.EntireRow.Hidden = False
Else
cageRow.EntireRow.Hidden = True
End If
' Box Row Logic
If UCase(boxToggle.Value) = "YES" Then
boxRow.EntireRow.Hidden = False
Else
boxRow.EntireRow.Hidden = True
End If
End Sub
Can you guys see any glooming issues with this code? I've no idea why I can't get it to work.
Bookmarks