if checked checkbox then add a cell.value

excel_lelkes

New Member
Joined
May 16, 2017
Messages
30
dear forum members:-)

I´ve several checkboxes (ActiveX)
I want to be able to do the following:
1) if checkbox1 is checked i.e. Range("G11").Value = True
2 ) Range.("J1").Value = Range("G11").offset(0,2).Value
3) if Range("G11").Value = True AND/OR Range("G12").Value = True
then Range.("J1").Value = Range.("J1").Value + Range("G12").offset(0,2).Value
and so on....
This long have I come on my own:
VBA Code:
Sub kryss()
Dim rng As Range
Dim cell As Range

With Sheet1
Set rng = .Range("G11:G19")
For Each cell In rng
If cell.Value = True Then
       .Range("J1").Value = cell.Offset(0, 2).Value + cell.Offset(0, 2).Value
End If
Next

End With
End Sub
But it´s not working as I wish:
it sums every "post"
twice

Please help me with the solution
Thanks in advance

Regards
Peter
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this

VBA Code:
.Range("J1").Value = .Range("J1").Value + cell.Offset(0, 2).Value
 
Upvote 0
Or this

VBA Code:
Sub kryss_2()
  Dim rng As Range
  Set rng = Sheet1.Range("G11:G19")
  Sheet1.Range("J1").Value = WorksheetFunction.SumIf(rng, True, rng.Offset(0, 2))
End Sub
 
Upvote 0
Or this

VBA Code:
Sub kryss_2()
  Dim rng As Range
  Set rng = Sheet1.Range("G11:G19")
  Sheet1.Range("J1").Value = WorksheetFunction.SumIf(rng, True, rng.Offset(0, 2))
End Sub
Thanks Dante for your time and knowledge!

I wasn´t aware of
VBA Code:
WorksheetFunction.SumIf()
A very elegant solution indeed

Regards
Peter
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,989
Members
452,541
Latest member
haasro02

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