VBA (Userform)

djb14128

New Member
Joined
Nov 14, 2019
Messages
27
Hi All,

I just would like to know why my code isn't working. Here is my VBA code:

VBA Code:
Private Sub OKButton_Click()

Dim i As Integer

'Make Sheet1 active
Estimates.Active

For i = 10 To 19

If DataCheckBox1.Value = True Then Cells(i, 2).Value = DateCheckBox1.Caption

If DataCheckBox2.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox2.Caption

If DataCheckBox3.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox3.Caption

If DataCheckBox4.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox4.Caption

If DataCheckBox5.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox5.Caption

If DataCheckBox6.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox6.Caption

If DataCheckBox7.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox7.Caption

If DataCheckBox8.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox8.Caption

If DataCheckBox9.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox9.Caption

If DataCheckBox10.Value = True Then Cells(i, 2).Value = Cells(i, 2).Value & " " & DateCheckBox10.Caption

End Sub



Private Sub ClearButton_Click()

Call UserForm_Initialize

End Sub

Private Sub CancelButton_Click()

Unload Me

End Sub

Private Sub CommandButton1_Click()

End Sub

Private Sub UserForm_Initialize()

'Uncheck DataCheckBoxes
DateCheckBox1.Value = False
DateCheckBox2.Value = False
DateCheckBox3.Value = False

End Sub

Thanks in advance.

Kind regards,
Ian
 
You where first looking at column A for the first blank, now you seem to be looking at col C, but you are putting the values in col B, none of which makes any sense.
Try it like
VBA Code:
Dim NextRow As Long
NextRow = Worksheets("Estimates").Range("B" & Rows.Count).End(xlUp).Offset(1).Row
If CheckBox1.Value = True Then Cells(NextRow, 2).Value = CheckBox1.Caption

If CheckBox2.Value = True Then Cells(NextRow, 2).Value = Cells(NextRow, 2).Value & CheckBox2.Caption
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I am putting the values in col B, but I want to put them in a range of empty cells in col B. For example, B10 to B19.
 
Upvote 0
Do they need to go below existing data in col B?
 
Upvote 0
Elements.png
 
Upvote 0
That does not answer my question.
 
Upvote 0
Let's start from the beginning & please remember that I cannot see your spreadsheet, have no idea what your end goal is & do not know what you are trying to do.
With that in mind, can you please describe, in words, what you want to happen?
 
Upvote 0
For example,

If I have various options to choose from: Ca, P, F, Na, Mg. And if I didn't tick/check Ca in the check box. I don't mind what order the ticked elements are placed, as long as they are in the range B10 to B19.
 
Last edited:
Upvote 0
In that case use the code that dmt32 supplied in post#13
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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