VBA Excel checkbox results with If statement not correct

chaz1010

New Member
Joined
Feb 16, 2014
Messages
2
Hi Guys,

Hope you are well. I keep on going around in circles and really need some help.
Okay, so I have got two worksheets. The first worksheet is called 'sheet1' and has two checkbox's called 'check1' and 'check2' and a button which pressed, executes the below code. The second worksheet is called 'results'.

The worksheet 'results' is as follows : A1 = Monday, B1 = 1, C1 = 1
A2 = Tuesday, B2 = 1, C2 = -4146
A3 = Wednesday, B3 = -4146, C3 = 1
A4 = Thursday,B4 = -4146, C4 = -4146

Depending on the checkboxes ticked I want the below result to appear in ‘sheet1’:
1)Check1 = ticked, check2 = ticked=> A1 = Monday, B1 = 1, C1 = 1 (works fine)
2)Check1 = ticked, check2 = not ticked=> A1 = Monday, B1 = 1, C1 = 1
A2 = Tuesday, B2 = 1, C2 = -4146 (does not work)
3)Check1 = not ticked, check2 = ticked=> A1 = Monday, B1 = 1, C1 = 1
A2 = Wednesday, B2 = -4146, C2 = 1(does not work)
4)Check1 = not ticked, check2 = not ticked=>A1 = Thursday,B1 = -4146, C1 = -4146 (works fine)

I am not sure where I am going wrong. I searched all over the web and loads of forums and can’t find a solution. It probably something really easy for you guys to resolve
If you could help me, I would greatly appreciated it! :-)
Thanks
Chaz

****CODE*********
Sub Macro1()

Dim w As Long
Dim s As Long
w = 1
s = 1
Do While Worksheets("results").Range("A" & w) <> ""

If ActiveSheet.Shapes("check1").ControlFormat.Value = Worksheets("results").Range("B" & w) And ActiveSheet.Shapes("check2").ControlFormat.Value = Worksheets("results").Range("C" & w) Then


Worksheets("sheet1").Range("A" & s) = Worksheets("results").Range("A" & w)
Worksheets("sheet1").Range("B" & s) = Worksheets("results").Range("B" & w)
Worksheets("sheet1").Range("C" & s) = Worksheets("results").Range("C" & w)
s = s + 1
End If
w= w + 1
Loop
End Sub
 
Hi Peter,
My bad, I wasn't aware that mrexcel.com and excelforum.com were the same website.
It wont happen again.
Thanks, Chaz
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top