Code to remove everything but date in

KORKIS2

Board Regular
Joined
Jun 5, 2015
Messages
143
HvH-Ab-150512-06

Changed to this--->150512

Here is the format the date will change depending on the day
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
We need to know all the rules (variations) of what this starting string can look like.
Will there always be the same number of characters before and after it?
Or will there always be two dashes before it and on after it?
 
Upvote 0
HvH-Ab-150512-06

Changed to this--->150512

Here is the format the date will change depending on the day
Is your text always structured like this?

text dash text dash date dash number

If not, then give us a better sense of how it could look.
 
Upvote 0
Yes it is always structured this way and its all in one column and its not always the same amount of rows and so therefore it should be in macro I think
I really appreciate the help guys
 
Upvote 0
Yes it is always structured this way and its all in one column and its not always the same amount of rows and so therefore it should be in macro I think
You can do it using Excel's Replace dialog box using the same two replacements that I used in the macro below...
Code:
Sub DateOnly()
  Columns("A").Replace "*-*-", "", xlPart
  Columns("A").Replace "-*", "", xlPart
End Sub
 
Upvote 0
Im guessing I plug in my parameters somewhere in here I don't quite understand the format

Sub DateOnly()
Columns("A").Replace "*-*-", "", xlPart
Columns("A").Replace "-*", "", xlPart
End Sub
 
Upvote 0
Im guessing I plug in my parameters somewhere in here I don't quite understand the format

Sub DateOnly()
Columns("A").Replace "*-*-", "", xlPart
Columns("A").Replace "-*", "", xlPart
End Sub

There is nothing for you to change.. the code I posted should be used as written... just copy/paste it into the code module.
 
Upvote 0
This is what I did

Sub DateOnly()
Columns("G").Replace "HvH-Ab-150512-06", "150512-06", xlPart
Columns("G").Replace "150512-06", "150512", xlPart
End Sub
 
Upvote 0
I tried playing with the range that doesnt seem to work either


Sub DateOnly22()


Range(G3 & ":" & G11).Replace "HvH-Ab-150512-06", "150512-06", xlPart
Range(G3 & ":" & G11).Replace "150512-06", "150512", xlPart
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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