Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Have userform & reams of code!

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)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Have userform & reams of code!

Hi Mark,

A bit simpler

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
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
If s = "" Then 'i.e. if no number is entered then display msgbox
MsgBox "You must tell how many products are going on this pallet!",
_
vbInformation
ElseIf s = "1" Then
Frame2.Visible = True
ElseIf s = "2" Then
Frame2.Visible = True
Frame3.Visible = True
ElseIf s = "3" Then
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = True
ElseIf s "3" Then
MsgBox "You have entered " & s & ". The max is 3!", _
vbInformation
End If
End Sub


--

HTH

RP

"Mark (InWales)" wrote in message
...
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)




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Have userform & reams of code!

Hi Bob

A bit simpler, it felt as if I was writing a book!

Many thanks Bob for taking the time

Mark


"Bob Phillips" wrote in message
...
Hi Mark,

A bit simpler

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
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
If s = "" Then 'i.e. if no number is entered then display msgbox
MsgBox "You must tell how many products are going on this pallet!",
_
vbInformation
ElseIf s = "1" Then
Frame2.Visible = True
ElseIf s = "2" Then
Frame2.Visible = True
Frame3.Visible = True
ElseIf s = "3" Then
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = True
ElseIf s "3" Then
MsgBox "You have entered " & s & ". The max is 3!", _
vbInformation
End If
End Sub


--

HTH

RP

"Mark (InWales)" wrote in message
...
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)






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Have userform & reams of code!

Mark,
See if this helps.
<Air Code
Dim s as long
s=val(Text2.Text)

select case s
case 0
MsgBox "You must tell us how many products are going on this pallet!",
vbInformation

case 3
MsgBox "You have entered " & s & ". Which bit of Max 3 do you not
understand?", vbInformation
end select

Frame2.Visible = ((s0) and (s<=3))
Frame3.Visible = ((s1) and (s<=3))
Frame4.Visible = ((s2) and (s<=3))
</Air Code

NickHK

"Mark (InWales)" wrote in message
...
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)




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UserForm code help needed. madbloke[_12_] Excel Programming 0 September 23rd 04 01:47 PM
UserForm code help needed. madbloke[_9_] Excel Programming 1 September 23rd 04 10:53 AM
UserForm code help needed. madbloke[_8_] Excel Programming 1 September 22nd 04 07:05 PM
Amount of code in UserForm RB Smissaert Excel Programming 7 December 20th 03 07:16 PM
VBA code for Userform Martin Los Excel Programming 4 December 5th 03 03:04 PM


All times are GMT +1. The time now is 12:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"