Hi, I am new to the forums and new to macros as well. I appreciate any help that you can give me.
What I'm trying to do is have two drop down lists that are right next to each other, this is already done, and have a macro check these two lists. So far this is working. Then depending on what is entered into the cells, the macro will take data from another tab and insert it into another cell on the first page. I've accomplished this with one cell and it works fine. However whenever I try to make it import two values, which are right next to each other, it gives me the error "value" of object "range" failed. Below is a part of my code, there are many more if statements because there are many items in the drop down list, however it is not necessary to upload the entirety of it. I'm sure there may be better ways to write this rather than a TON of if statements, but I started it out this way so I'm continuing onward.
Private Sub Worksheet_Change(ByVal Target As Range)
a = ActiveCell.Row
'Coil Handling Equipment
If Worksheets("Automated Production Equipment").Cells(a, 3).Value = "Coil Handling Equipment" And Worksheets("Automated Production Equipment").Cells(a, 4).Value = "Perfecto" Then
Worksheets("Automated Production Equipment").Cells(a, 5).Value = Worksheets("Production Equipment").Cells(13, 5).Value
Worksheets("Automated Production Equipment").Cells(a, 6).Value = Worksheets("Production Equipment").Cells(13, 6).Value
ElseIf Worksheets("Automated Production Equipment").Cells(a, 3).Value = "Coil Handling Equipment" And Worksheets("Automated Production Equipment").Cells(a, 4).Value = "ASC" Then
Worksheets("Automated Production Equipment").Cells(a, 5).Value = Worksheets("Production Equipment").Cells(14, 5).Value
Else
Worksheets("Automated Production Equipment").Cells(a, 5).Value = 0
End If
End Sub
Edit: I have the macro in the sheets own module, just fyi. Also, the line I am trying to is "Worksheets("Automated Production Equipment").Cells(a, 6).Value = Worksheets("Production Equipment").Cells(13, 6).Value" Without this line everything works fine.
Edit 2: I solved this by using Application.EnableEvents = False. Before any of my if statements I use Application.EnableEvents = True, then when I get into my if statement and it is found try, I first set it equal to False then do everything and then when it exits the if statement but before it ends sub, i set it back to true.
Bookmarks