Copying and pasting ceratin sections of text

ir26121973

Board Regular
Joined
Mar 7, 2006
Messages
79
Hi,

Wonder if someone maybe able to help me please. This is fairly complicated to explain and I am really quite new to VB.

Some time ago I posted a query I had on how to pick specific error codes out of a whole string of text.

e.g. The error is Error 15.1 and it has occured.......

From the above I just wanted to pick out 'Error 15.1'

I was kindly given the code below to use which works a treat.

SELECT MyTable.MyField, Mid([MyField],InStr([MyField],"Error")+6,4) AS ErrorCode FROM MyTable;

However new errors have been added that are longer in length e.g. Error 153.1. Now I know that I can, and have changed the 6,4 element of the code to take these longer codes into account.

The problem I have now, is that because I have made these changes, for the shorter codes, it not only takes the Error Code but some of the text after it aswell.

Is there anyway please that the code can take into both the short and long codes.

The one common thing is that they all start with the word 'Error' followed by numerics, then text. I'm not sure whether the code could be designed to say to look for the word 'Error' and then take out what follows until it gets to the next letter, thus taking out the short and long error codes.

Many thanks

Chris
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Within the code you were given, you know that you can change the 6,4 to 6,5 to get a longer error code. What you need is code to change the 4 to be whatever length the error code actually is. The following will do that. Replace the 4 with the following code and it should work.

InStr(InStr(MyField,"Error")+6, MyField, " ") - (InStr(MyField,"Error")+6)

HTH,
 
Upvote 0
Vic,

Thanks for this, I really appreciate your help. The application I have is at work so I will test this tomorrow.

Sorry to sound a bit thick, but am I right in thinking that I use my existing code up to the number 6 then the put this in after it.

Many thanks once again

Chris
 
Upvote 0
Exactly right. The code replaces the 4 which is the LENGTH of the error code. At first you knew it would always be a length of 4, but now it can be longer, therefore you need code that will look at the length of the error code itself, and choose that length.
 
Upvote 0
Vic,

Just thought I'd let you know that the testing went great.

Thanks very much for your time and trouble.

Regards

Chris
 
Upvote 0

Forum statistics

Threads
1,225,762
Messages
6,186,895
Members
453,384
Latest member
BigShanny

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