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
 
Glad it's sorted & thanks for the feedback
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi,

There is a difference between the following;

VBA Code:
If something = True then do_something

and this;

VBA Code:
If something = True then
      do_something
end if

The main issue here is single line *IF* statements do not require the *END IF* syntax.....
If your *IF* statement has further code below it (after a line break) THEN you will need the *END IF* syntax...


Try this,

VBA Code:
Private Sub OKButton_Click()

Worksheets("Estimates").Active

Dim i As Integer

For i = 10 To 19

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

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

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

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

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

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

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

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

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

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

Next i

End Sub


Hope this helps,
BenR

** Edit ** @ Fluff - sorry mate, just realised this thread was completed - I'm new to the boards and didn't realise it had been solved.
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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