Need Code Snippet Help

A

Angyl

This isn't working quite right. I want the code to check which box is
checked and put one thing in the cell, and if neither of them are cheked to
put nothing in, but I'm always just getting the second choice (6789)
irregardless of the checkbox status.

Pls help.

With tblTarget
If Check1.Checked = True Then
.Cell(1, 1).Range.Text = "12345"
If Check2.Checked = True Then
.Cell(1, 1).Range.Text = "6789"
End If
End With
 
L

larrysulky

With tblTarget
If Check1.Checked = True Then
.Cell(1, 1).Range.Text = "12345"
If Check2.Checked = True Then
.Cell(1, 1).Range.Text = "6789"
End If
End With

I'm not clear on your intended logic. You are missing an End If
statement somewhere, presumably immediately after the first End If. In
that case, what you have coded here will only check Check2 if Check1
was checked. It appears that the logic you want to achieve is this:

a) If Check1 and Check2 are both checked, use value "6789")
b) if Check1 only is checked, use value "12345"
c) if neither Check1 nor Check2 is checked, or if Check2 only is
checked, do not use any value (for which case you should probably
initialise the value to nil).

Correct?
 
N

NZ VBA Developer

Just change

If Check2.Checked = True Then

to

ElseIf Check2.Checked = True Then

and just to be safe add another line before the "End If"

Else: .Cell(1, 1).Range.Text =""

That should fix it.
 
A

Angyl

Thanks!!

NZ VBA Developer said:
Just change

If Check2.Checked = True Then

to

ElseIf Check2.Checked = True Then

and just to be safe add another line before the "End If"

Else: .Cell(1, 1).Range.Text =""

That should fix it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top