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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,215,220
Messages
6,123,698
Members
449,117
Latest member
Aaagu

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