VBA Macro: MID - Pulling Data from Inside Strings

Sphinx404

Board Regular
Joined
May 2, 2015
Messages
186
Office Version
  1. 365
Platform
  1. Windows
You'll notice the last 3 entries in the data set begin with "006", however, the alphabetic characters are at the end of the string. This poses a new question, I can account for the what the string begins with and what the string ends with, but I'm stuck on how to write the code to pull the information in-between. Below my "non-working" code is in as I have attempted to create a rule that accounts for these random outliers.

I need the 8 numeric values in-between... between the "006" & the "MSP","ATL", etc.

Select Case True
Case Left(mycell.Value, 3) = "006"
If IsNumeric(Right(mycell.Value, 8)) Then
mycell.Offset(, 16).Value = Right(mycell.Value, 8)
End If
Case Left(mycell.Value, 2) = "06"
If IsNumeric(Right(mycell.Value, 8)) Then
mycell.Offset(, 16).Value = Right(mycell.Value, 8)
Case Left(mycell.Value, 3) = "006"
If Not IsNumeric(Right(mycell.Value, 8)) Then
mycell.Value = Mid(mycell.Value, 3, 8)
End If
End Select


Ideas?

[TABLE="class: cms_table, width: 114"]
<tbody>[TR]
[TD]006ATL95210452[/TD]
[/TR]
[TR]
[TD]006MSP95212176[/TD]
[/TR]
[TR]
[TD]006MSP95212176[/TD]
[/TR]
[TR]
[TD]006DTW95214475[/TD]
[/TR]
[TR]
[TD]006ATL95219924[/TD]
[/TR]
[TR]
[TD]006ATL95219924[/TD]
[/TR]
[TR]
[TD]006ATL97146350[/TD]
[/TR]
[TR]
[TD]006MSP95228184[/TD]
[/TR]
[TR]
[TD]006MSP95230612[/TD]
[/TR]
[TR]
[TD]00695446750MSP[/TD]
[/TR]
[TR]
[TD]00695466766MSP[/TD]
[/TR]
[TR]
[TD]00695466044MSP[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Upvote 0
I apologize. I looked for a "Delete thread Topic" button but I could not locate one. I wanted to delete this, but was (and still am) unaware of how.

Thanks. Won't happen again.

Steve
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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