Answer the question
In order to leave comments, you need to log in
Magic error 1004?
Hi friends! Here is an interesting story) I explain! There are several repeating conditions (12 pieces), I check one condition, hurrah, it works! And here in a chain of conditions refuses to work. Throws error 1004. Refers to Worksheets("max").Range("C3").Interior.Color = vbRed when debugging. What to do, people! Code below
'3
If Worksheets("max").Range("C3").Value = Worksheets("sheet").Range("B1").Value Then
Worksheets("max").Range("C3").Value = Worksheets("sheet").Range("B3").Value
Worksheets("max").Range("С3").Interior.Color = vbGreen
ElseIf Worksheets("max").Range("C3").Value = Worksheets("sheet").Range("C1").Value Then
Worksheets("max").Range("C3").Value = Worksheets("sheet").Range("C3").Value
Worksheets("max").Range("С3").Interior.Color = vbRed
End If
'4
If Worksheets("max").Range("C4").Value = Worksheets("sheet").Range("B1").Value Then
Worksheets("max").Range("C4").Value = Worksheets("sheet").Range("B4").Value
Worksheets("max").Range("С4").Interior.Color = vbGreen
ElseIf Worksheets("max").Range("C4").Value = Worksheets("sheet").Range("C1").Value Then
Worksheets("max").Range("C4").Value = Worksheets("sheet").Range("C4").Value
Worksheets("max").Range("С4").Interior.Color = vbRed
End If
'5
If Worksheets("max").Range("C5").Value = Worksheets("sheet").Range("B1").Value Then
Worksheets("max").Range("C5").Value = Worksheets("sheet").Range("B5").Value
Worksheets("max").Range("С5").Interior.Color = vbGreen
ElseIf Worksheets("max").Range("C5").Value = Worksheets("sheet").Range("C1").Value Then
Worksheets("max").Range("C5").Value = Worksheets("sheet").Range("C5").Value
Worksheets("max").Range("С5").Interior.Color = vbRed
End If
Answer the question
In order to leave comments, you need to log in
Why would you use Range when you are accessing a single cell. Sheets better accustom themselves to name always through Set. Use Cells instead of Range.
Set WBMax = thisworkbook.worksheets("max")
Set WBSheet = thisworkbook.worsheets("sheet")
If WBMax.Cells(1,3).Value = WBMSheet.Cells(1,2).Value Then
WBMax.Cells(3,3).Value = WBMSheet.Cells(3,2).Value
WBMax.Cells(3,3).Interior.Color = RBG(1,1,1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question