answer to Rick
Sorry, but it was so much scrolling, that it's better to answer
you in a new post.
I don't think it is better to do that at all. This message, and any answers
it receives, will not be connected to your previous thread in the archive (I
am thinking Google here); so anyone following the original thread will not
know it has been continued and may not see any follow ups. It is always
better to stick with the original thread.
The point is; -if nothing is written by user in textbox3, the existing
text in the cell that relate to textbox3 will not be changed.
if this still is confusing, I can send u the file
No, I really wouldn't have the time to study/learn your spreadsheet just for
a single answer. But I would like to clarify my previous post. I had made an
assumption that wasn't true, but your code is still flawed (but not
harmfully so, at least I don't think it is harmful). Here is my problem. You
wrote this code...
iCtr = ComboBox1.Value
Select Case [iCtr]
Case Is = 1
Range("B4") = Me.TextBox2
If TextBox3.Text = "" Then GoTo line1
Range("C4") = Me.TextBox3
line1:
Case Is = 2
Range("B5") = Me.TextBox2
If TextBox3.Text = "" Then GoTo line2
Range("C5") = Me.TextBox3
line2:
Case Is = 3
Range("B6") = Me.TextBox2
If TextBox3.Text = "" Then GoTo line3
Range("C6") = Me.TextBox3
line3:
.....<<rest of code snipped.....
Let's assume iCtr is 1. When you enter the Select Case block, iCtr meets the
first Case statement's condition, so that code executes. It sets B4 equal to
the contents of TextBox2. THEN, it looks at the contents of TextBox3 and IF
there is nothing in that TextBox, it jumps to the 'line1' label in order to
continue execution. However, NO ADDITIONAL CODE inside the Select Case block
will be executed... the next statement that will be execute is the one that
comes after the End Select statement. You have labels in front of each of
your Case statements and Goto statements that attempt to direct code
execution to them... and my question is why? The code in a Case statement's
block will natually fall through to the End Select statement when all the
code in the block has been executed.... there is no need, or benefit, trying
to direct the execution to other locations within the Select Case block.
Here is a short demo to show you the problem I am trying to highlight.
Consider this code....
Dim iCtr As Long
iCtr = 1
Select Case iCtr
Case Is = 1
GoTo line1
MsgBox "Will I be executed?"
line1:
Case Is = 2
MsgBox "I won't be executed if iCtr = 1"
End Select
Neither one of the MsgBox statements will be executed. Do you see the
parallel? If iCtr equals 1, the GoTo line1 statement will do what your empty
TextBox3 will do, send execution to the 'line1' label; HOWEVER, no other
code in the Select Case block will be executed, especially the "I won't be
executed if iCtr=1" MessageBox that is in the Case block that the GoTo
statement appears to be sending code execution to.
Rick
|