At the moment I'm working on making a working code smaller using an array. I will explain the code shortly;
If a certain part is required to be in a datasheet (this worksheet is called "High Pressure Grinding Rolls"), then the user can define this by putting in value "a" on Sheets("Invulformulier"). Now there are several parts which can be on the datasheet if the cell value is "a". If we have "partA", "partB" and "partC", the RangeName of the cell will be the name of the part on Sheets("Invulformulier"). The RangeName of the range on Sheets("High Pressure Grinding Rolls") will be the name of the part + "1". For example "partA1". This range must be hidden depending on if the user puts in "a" for "partA".
This is the code I used and worked, but is specific to the cell names:
Sub Hidecellv1 ()
If Range("partA").Value = "a" Then
Sheets("High Pressure Grinding Rolls").Range("partA1").EntireRow.Hidden = False
ElseIf Range("partA").Value = "" Then
Sheets("High Pressure Grinding Rolls").Range("partA1").EntireRow.Hidden = True
End If
End Sub
This code is very specific and I want to make an array. This is what I have so far:
Sub Hidecellwitharray ()
Dim rngName As Range
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In Range("Checkbox") 'Where user puts in value "a" or not
If cell.Value = "a" Then
Sheets("High Pressure Grinding Rolls").Range(RangeName & "1").EntireRow.Hidden = False
Else
Sheets("High Pressure Grinding Rolls").Range(RangeName & "1").EntireRow.Hidden = True
End If
Next cell
Application.ScreenUpdating = True
End Sub
The searching for value "a" for every part works, but I can't get it to work to hide the parts in the datasheet if value "a" is or isn't inserted. How do I refer to a variable RangeName?