Problems with Select Case Matching

Oberon70

Board Regular
Joined
Jan 21, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
For some reason my case select is not matching with the variable. I only have

VBA Code:
Sub CrtWorkFlw()

Dim Lastrow As Double
Dim AgtName As String
Dim InvNum As String

Lastrow = wsSupSheet.Cells(Rows.Count, "A").End(xlUp).Row

'AgtName = Trim(wsInvDtls.Range("B3").Value)
'InvNum = wsInvDtls.Range("B1").Value

AgtName = Trim(wsInvDtls.Range("B7").Value)
InvNum = wsInvDtls.Range("B8").Value

Select Case AgtName
    Case AgtName = "Wayne Tech"
        AgtName = "WayneTech"
    Case AgtName = "Lex Corp"
        AgtName = "LexCorp"
End Select

wsSupSheet.Range("A" & Lastrow & ":" & "C" & Lastrow).Offset(1).Merge
wsSupSheet.Range("A" & Lastrow & ":" & "C" & Lastrow).Offset(1) = (AgtName & " " & InvNum)
             
Debug.Print AgtName

End Sub

Any idea why?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
What exactly is the value of AgtName?
 
Upvote 0
Your Case statements are wrong. They should be:

Code:
Select Case AgtName
    Case "Wayne Tech"
        AgtName = "WayneTech"
    Case "Lex Corp"
        AgtName = "LexCorp"
End Select

although it looks like you could just replace spaces and skip the Select Case altogether.
 
Upvote 0
Solution
The agent name is taken from another worksheet, where the name is taken from a statement.

1648723568894.png
 
Upvote 0
It is working now with the change to

VBA Code:
Select Case AgtName
    Case "Wayne Tech"
        AgtName = "WayneTech"
    Case "Lex Corp"
        AgtName = "LexCorp"
End Select

but I have put the code
VBA Code:
=CODE(MID(B7,6,1))
and it has returned 32
 
Upvote 0
32 is correct, I had missed the fact that you had Case AgtName = "Wayne Tech" rather than Case "Wayne Tech"
 
Upvote 0
All good, I really appreciate everyone's help. I had one of those Eureka moments today that is going to likely help me get caught up on receipting for my work.

The main system I use allows you to paste into it. There are three sections to receipting.

1. T Screen - which is where I can enter a max of 16 funds paid.
2. Transactions Screens - where you can enter 6 transactions
3. Final Screen, which is were you enter the opposite of the transactions you entered before. This screen has a max of 12 entries.

I manually entered the information into an excel spreadsheet and figured out the way the information needs to be spaced in the spreadsheet. I am then able to copy and paste the information into the program.

It basically means in about 10 key presses I have receipted 16 entries in probably about 10-20 seconds instead of about 10 minutes.

So, I am working hard to pull the information from a statement and and enter it onto a new worksheet in the format I found that works.

The next part is going to be the hardest part, where I create loops to enter the information onto the spreadsheet as this needs to be dynamic.

I am really excited as work has been extremely stressful due unplanned leave in my team and being a team member down and being the 2nd responsible for the team I have a lot of other task to manage, but I enjoy it and have been at the role for 13 years.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,300
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top