VBA Macro: If Begins With Then

Sphinx404

Board Regular
Joined
May 2, 2015
Messages
186
Office Version
  1. 365
Platform
  1. Windows
I am failing dramatically at writing the code for this, what I thought would be a simple macro.

This initial process is the following:

IF E2 begins with “006***” THEN return the last 8 characters in the string in U2, only IF the final 8 characters are numbers, THEN return “N/A” in U2, & IF there are no characters after “006***” THEN return “RESEARCH” in U2.

Else

IF E2 begins with “1Z” THEN return “UPS” in U2

Else

IF E2 begins with “UPS” THEN return “UPS” in U2

Else

IF E2 contains “1Z” in string THEN return “UPS” in U2

Else

IF E2 contains “” (blank) in string THEN return “Research” in U2

This macro needs to be setup to work on the same report I pull everyday (its static and always the same), and needs to encompass all entries in the "E" Column.

The Data in column E looks similar to this:

006ATL95210452
006MSP95212176
006MSP95212176
006ATL95219924
006ATL95219924
006ATL97146350
006MSP95230612
006ATL95234230
1Z22A9000273228290
006ATL95241941
UPS1Z22A9000276792808
UPS 1Z58F0260240282635
006ATL95248672
FEDEX#645003799830
006ATL95252010
006ATL95401692

Any help from you MACRO kings would be appreciated!

Steve

<colgroup><col></colgroup><tbody>
</tbody>
 
I'm going to work at it. Let you know if I'm able to figure it out, right now your code above works. I'm going to see my small VBA brain can work its muscles to produce a new rule to exclude other undesirable information. Thanks a lot for your help, when you start teaching classes, let me know. :cool:


695236035
695235836
695235302
00695446750MSP95446750
00695466766MSP95466766
695493042
006DTWDTW
00695466044MSP95466044
ATL00695479042
695580973
695513655
676183925
006ATAT
676405140
695589830
695589841
695618924
695618390
695580181
695619285
695619521
006MSP34504901-39:05167MSP34504

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,216,520
Messages
6,131,135
Members
449,626
Latest member
Stormythebandit

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