Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Select Case Picking up number

I have this code

Private Sub cmb1_Change()

Dim sVar As String
sVar = cmb1.Text

With cmb1
Select Case Left(.Text, 1)
Case D:
txtBAID.Text = sVar
Case 7:
txtPLID.Text = sVar
Case 2:
txtSAVID.Text = sVar
Case A:
txtMORID.Text = sVar
Case Else:
txtCCID.Text = sVar
End Select
End With

End Sub

If I select one of these variables:

D12345
712345
212345
A12345
112345

The ones beginning with 7, 2, and 1 work. But the D and A
aren't picked up by the select case and just go to case
else.

Can anyone explain why, and how I get around this.

Thanks

Dean
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Select Case Picking up number

to use string values in your select case, you need to
enclose the value in quotes e.g. Case "D", otherwise VBA
will look for a variable D, rather than the value.

Steve
-----Original Message-----
I have this code

Private Sub cmb1_Change()

Dim sVar As String
sVar = cmb1.Text

With cmb1
Select Case Left(.Text, 1)
Case D:
txtBAID.Text = sVar
Case 7:
txtPLID.Text = sVar
Case 2:
txtSAVID.Text = sVar
Case A:
txtMORID.Text = sVar
Case Else:
txtCCID.Text = sVar
End Select
End With

End Sub

If I select one of these variables:

D12345
712345
212345
A12345
112345

The ones beginning with 7, 2, and 1 work. But the D and

A
aren't picked up by the select case and just go to case
else.

Can anyone explain why, and how I get around this.

Thanks

Dean
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Select Case Picking up number

Hi Dean,

You need to add quotes to D otherwise it expects D to be a variable.
So modify code to
Case "D"

Dean Knox wrote:
I have this code

Private Sub cmb1_Change()

Dim sVar As String
sVar = cmb1.Text

With cmb1
Select Case Left(.Text, 1)
Case D:
txtBAID.Text = sVar
Case 7:
txtPLID.Text = sVar
Case 2:
txtSAVID.Text = sVar
Case A:
txtMORID.Text = sVar
Case Else:
txtCCID.Text = sVar
End Select
End With

End Sub

If I select one of these variables:

D12345
712345
212345
A12345
112345

The ones beginning with 7, 2, and 1 work. But the D and A
aren't picked up by the select case and just go to case
else.

Can anyone explain why, and how I get around this.

Thanks

Dean


--

Cheers
Andy

http://www.andypope.info

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
picking largest number dnmusic Excel Worksheet Functions 4 October 16th 09 03:41 PM
Select case Hein Excel Discussion (Misc queries) 2 October 22nd 08 07:06 AM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Picking correct number with < scott Excel Discussion (Misc queries) 2 October 21st 07 10:21 AM
Help picking a random number from a given distribution McGinty Excel Worksheet Functions 6 October 26th 06 02:57 PM


All times are GMT +1. The time now is 10:06 PM.

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

About Us

"It's about Microsoft Excel"