M
Mark \(InWales\)
Hello world
As you know I am new to VBA and trying to learn but what I could really do
with is some pointers in shortening code etc. The following code (not
written with the macro recorder!) is very long but I don't seem to be able
to shorten it with my limited knowledge... I also have a problem with
putting Else & End if's in the wrong slot - but you probably guessed that!
Anyone want to try and teach an old dog some new tricks.
Private Sub Command4_Click()
'This bit makes the correct number of frames visible depending on the user
input
Dim s As Variant
s = Text2.Text
If s = "" Then 'i.e. if no number is
entered then display msgbox
MsgBox "You must tell us how many products are going on this pallet!",
vbInformation
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Else
End If
On Error Resume Next
If s = "1" Then
Frame2.Visible = True
Frame3.Visible = False
Frame4.Visible = False
Else
End If
If s = "2" Then
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = False
Else
If s = "3" Then
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = True
Else
If s > "3" Then
MsgBox "You have entered " & s & ". Which bit of Max 3 do you not
understand?", vbInformation
Else
End If
End If
End If
End Sub
TIA
Mark (InWales)
As you know I am new to VBA and trying to learn but what I could really do
with is some pointers in shortening code etc. The following code (not
written with the macro recorder!) is very long but I don't seem to be able
to shorten it with my limited knowledge... I also have a problem with
putting Else & End if's in the wrong slot - but you probably guessed that!
Anyone want to try and teach an old dog some new tricks.
Private Sub Command4_Click()
'This bit makes the correct number of frames visible depending on the user
input
Dim s As Variant
s = Text2.Text
If s = "" Then 'i.e. if no number is
entered then display msgbox
MsgBox "You must tell us how many products are going on this pallet!",
vbInformation
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Else
End If
On Error Resume Next
If s = "1" Then
Frame2.Visible = True
Frame3.Visible = False
Frame4.Visible = False
Else
End If
If s = "2" Then
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = False
Else
If s = "3" Then
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = True
Else
If s > "3" Then
MsgBox "You have entered " & s & ". Which bit of Max 3 do you not
understand?", vbInformation
Else
End If
End If
End If
End Sub
TIA
Mark (InWales)