Hi Guys,
New to the forum as well to VBA. I am in the process of building a spreadsheet and am struggling a little bit with some elementary VBA code/layout. Here is what I am trying to accomplish. On Sheet1, I am trying to have a user enter info that can ultimately be used on other sheets for more in depth calculations. For example, in cell B7, I am asking the user (car dealership) to select the total number of Cars that they will be purchasing (option from drop down list of 0 through 9). Then I need to gather data on each one of those individual cars (make, model, front wheel drive/rear/all, etc... you get the point). I don't want to have a separate detailed entry table for 9 cars displayed if they are only purchasing 3, so my goal is to have them enter the total # of cars they are purchasing, and then only displaying detailed entry tables for 3 of those cars rather than all 9. This is the code I have to accomplish this task and it is working beautifully.
Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$B$7" Then Exit Sub
If Target.Value = 0 Then Rows("8:33").EntireRow.Hidden = True
If Target.Value = 1 Then Rows("8:10").EntireRow.Hidden = False
If Target.Value = 2 Then Rows("8:13").EntireRow.Hidden = False
If Target.Value = 3 Then Rows("8:16").EntireRow.Hidden = False
If Target.Value = 4 Then Rows("8:19").EntireRow.Hidden = False
If Target.Value = 5 Then Rows("8:22").EntireRow.Hidden = False
If Target.Value = 6 Then Rows("8:25").EntireRow.Hidden = False
If Target.Value = 7 Then Rows("8:28").EntireRow.Hidden = False
If Target.Value = 8 Then Rows("8:31").EntireRow.Hidden = False
If Target.Value = 9 Then Rows("8:33").EntireRow.Hidden = False
End Sub
The problem is that I want to do the same for Trucks, Vans, Buses, & Motorcycles. These are completely independent of the car value above, but nevertheless, still trying to accomplish the same exact task. Given my lack of experience with VBA, I am just not sure how to integrate the following code into the original code and have it work the way I need it to. As you can see, its identical, just applies to a different set of rows within the spreadsheet.
If Target.Address <> "$B$35" Then Exit Sub
If Target.Value = 0 Then Rows("36:61").EntireRow.Hidden = True
If Target.Value = 1 Then Rows("36:38").EntireRow.Hidden = False
If Target.Value = 2 Then Rows("36:41").EntireRow.Hidden = False
If Target.Value = 3 Then Rows("36:44").EntireRow.Hidden = False
If Target.Value = 4 Then Rows("36:47").EntireRow.Hidden = False
If Target.Value = 5 Then Rows("36:50").EntireRow.Hidden = False
If Target.Value = 6 Then Rows("36:53").EntireRow.Hidden = False
If Target.Value = 7 Then Rows("36:56").EntireRow.Hidden = False
If Target.Value = 8 Then Rows("36:59").EntireRow.Hidden = False
If Target.Value = 9 Then Rows("36:61").EntireRow.Hidden = False
Any help on this topic would be much appreciated. Again, sorry if this is elementary, I am just super green when it comes to VBA.
Thanks in advance for your help!
Bookmarks