Formula using VBA?

Rana Gray

Board Regular
Joined
Jan 26, 2023
Messages
56
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hey Everyone,

Sorry for the silly question but can someone help me with the VBA version of this formula: =IF($E13=TRUE,$B13,"")

Basically I don't want to put the formula directly in the cell where it can be overwritten, I also need it to apply to all rows (columns are fixed). All this does is if my checkbox is ticked the date in cell E13 gets copied into cell N13 etc. if it's not ticked then leave blank.

Thank you in advance!!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Something like this perhaps, though depending on where the code is, you may have to identify the specific worksheet name, and I am assumed you meant the date in cell B13 gets copied based on your formula:

VBA Code:
Private Sub CheckDate()
Dim c, t As Range
Set t = Range("E13:E20")
For Each c In t
    If c.Value = True Then Range("N" & c.Row).Value = Range("B" & c.Row).Value
Next c
End Sub
 
Upvote 0
Something like this perhaps, though depending on where the code is, you may have to identify the specific worksheet name, and I am assumed you meant the date in cell B13 gets copied based on your formula:

VBA Code:
Private Sub CheckDate()
Dim c, t As Range
Set t = Range("E13:E20")
For Each c In t
    If c.Value = True Then Range("N" & c.Row).Value = Range("B" & c.Row).Value
Next c
End Sub
This makes sense to me I just want to ask how to assign the "c" variable to "checkboxes" - I plugged this script in but nothing is happening. I placed it on "Sheet1". I'm certain I am missing something.
1698863547737.png

1698863592475.png
 
Upvote 0
This makes sense to me I just want to ask how to assign the "c" variable to "checkboxes" - I plugged this script in but nothing is happening. I placed it on "Sheet1". I'm certain I am missing something.
View attachment 101353
View attachment 101354
That's on me. You did say checkboxes, but I wrote the code to check individual cells. Are the checkboxes Form Controls or ActiveX Controls?
 
Upvote 0
I also have a lot of checkboxes I know I can do an if then code but I want to avoid having to code each check box
That's on me. You did say checkboxes, but I wrote the code to check individual cells. Are the checkboxes Form Controls or ActiveX Controls?
Active X - I know I can use an if then statement to code each individual checkbox but there are so many and it would just be time consuming
 
Upvote 0
I also have a lot of checkboxes I know I can do an if then code but I want to avoid having to code each check box

Active X - I know I can use an if then statement to code each individual checkbox but there are so many and it would just be time consuming
Are there more checkboxes beyond column E?
 
Upvote 0
Alright, so I don't think there is an easy way to identify which cell belongs to which checkbox without linking each one individually, or naming them in a way that we can use the name or part of the name to know which row it is on. Either way, that process is going to be tedious and time consuming at best.

There are some tricks you can use instead of check boxes if you are up for it.
 
Upvote 0
Alright, so I don't think there is an easy way to identify which cell belongs to which checkbox without linking each one individually, or naming them in a way that we can use the name or part of the name to know which row it is on. Either way, that process is going to be tedious and time consuming at best.

There are some tricks you can use instead of check boxes if you are up for it.
So I have already linked each checkbox to the cell it's being housed in if that helps :) so each cell in column E becomes true/false based on the checkbox already :) if that changes things
 
Upvote 0
So I have already linked each checkbox to the cell it's being housed in if that helps :) so each cell in column E becomes true/false based on the checkbox already :) if that changes things
The code SHOULD have worked then. If all the checkboxes are linked to their respective cells in column E, then it would be checking the cell value. I can still adjust the code to check the check boxes though instead of the cells.

I suppose one thing to test would be identifying the sheet name in the code as well:

VBA Code:
Private Sub CheckDate()
Dim c, t As Range
Dim ws As Worksheet
Set ws = Sheets("Monthly Tracker")
Set t = ws.Range("E13:E112")
For Each c In t
    If c.Value = True Then ws.Range("N" & c.Row).Value = ws.Range("B" & c.Row).Value
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

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