adding more code to an existing macro

V

VKachnow

Many thanks to those who helped me last week with my question of assigning
macro to checkboxes.
I now have a new related question. I am trying to add some new commands to
the undo portion of my checkbox macro and just tried to copy in the new code
next to what I already had, but I keep getting error messages.

This is the code for the new actions:

Range("G15").Select
Selection.ClearContents
Range("I15").Select
Selection.ClearContents
Range("C15").Select
ActiveCell.FormulaR1C1 = "=RC[4]*RC[6]"
Range("D15").Select

When I added it to the prexisting code, I added "Sheet 6" references and the
total code looked like this:

Sub CheckBox105_Click()

If Sheets("Step 4").DrawingObjects("Check box 105").Value > 0 Then
'Sheets("Step 6").Select
Sheets("Step 6").Range("C16").Interior.ColorIndex = 2
Sheets("Step 6").Range("G16").Interior.ColorIndex = 2
Sheets("Step 6").Range("I16").Interior.ColorIndex = 2
Else
Sheets("Step 6").Range("G16").Select
Selection.ClearContents
Sheets("Step 6").Range("I16").Select
Selection.ClearContents
Sheets("Step 6").Range("C16").Select
ActiveCell.FormulaR1C1 = "=RC[4]*RC[6]"
Sheets("Step 6").Range("C16").Interior.ColorIndex = 42
Sheets("Step 6").Range("G16").Interior.ColorIndex = 42
Sheets("Step 6").Range("I16").Interior.ColorIndex = 42
End If

End Sub

Any ideas why this does not work? Do I need to consolidate all the commands
that apply to a specific cell? Any insights would be much appreciated!
Thanks in advance!
 
M

mudraker

VKachnow



try this.
The 2nd version does the same as the 1st version combining several
actions into the one line of code



If Sheets("Step 4").DrawingObjects("Check box 105").Value > 0 Then
Sheets("Step 6").Range("C16").Interior.ColorIndex = 2
Sheets("Step 6").Range("G16").Interior.ColorIndex = 2
Sheets("Step 6").Range("I16").Interior.ColorIndex = 2
Else
Sheets("Step 6").Range("G16").ClearContents
Sheets("Step 6").Range("I16").ClearContents
Sheets("Step 6").Range("C16").FormulaR1C1 = "=RC[4]*RC[6]"
Sheets("Step 6").Range("C16").Interior.ColorIndex = 42
Sheets("Step 6").Range("G16").Interior.ColorIndex = 42
Sheets("Step 6").Range("I16").Interior.ColorIndex = 42
End If



OR



If Sheets("Step 4").DrawingObjects("Check box 105").Value > 0 Then
Sheets("Step 6").Range("C16,G16,I16").Interior.ColorIndex = 2
Else
Sheets("Step 6").Range("G16,I16").ClearContents
Sheets("Step 6").Range("C16").FormulaR1C1 = "=RC[4]*RC[6]"
Sheets("Step 6").Range("C16,G16,I16").Interior.ColorIndex = 42
End If
 
V

VKachnow

Thanks so much! I used the first version and it's working great. Really
appreciate your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top