VBA to delete everything after "m" in a selection

pltaine

New Member
Joined
May 9, 2018
Messages
8
Hi guys,

I am working with a rota and there is a grid with all the data with names across Row 6 and the dates of the year down Column A. In the grid are all sorts of entries, with "Off", "Holiday" etc but all shifts are written in the form "7am-6pm". I am looking to clear all the cells of everything apart from shift start time. I have managed to write one that clears all the which aren't in the "7am-6pm" form above, but am struggling to write one which will delete everything after the first "m" (from "am").

Would really appreciate some help on this.

Cheers
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
In VBA, the equivalent to the Excel FIND function is InStr.

So you could use the LEFT function along with InStr to just keep the left most characters.

strStart = LEFT(strStart, InStr("am-", strStart)+1)
 
Upvote 0

Forum statistics

Threads
1,215,344
Messages
6,124,407
Members
449,157
Latest member
mytux

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