VBA + macro + to copy and paste

llo

New Member
Joined
Jul 16, 2009
Messages
8
I need to <NOBR>copy</NOBR> only part of a cell that holds (06:00am - 03:00pm). I only need to <NOBR>copy</NOBR> the 06:00. And then paste the "06:00" onto another worksheet into one cell on it's own. And then mimic that <NOBR>process</NOBR> for the "03:00". Can someone assist? All this doing so with a <NOBR>macro</NOBR> (<NOBR>VBA</NOBR>)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Is that what is really in the cell and do you know if the cell is hence a text value, not a time and date format, meaning you want to parse the values into two sets, one before the dash and one after?
 
Upvote 0
Yes, that is exactly what is in the cell. I would like the time format without the "am" ( if possible) along with after the dash, the time format without the "pm", if possible. Each time pasted into two individual cells.
 
Upvote 0
Well, you stressed that you wanted VBA but you can accomplish this with formulas too.

If it is cell A1 that exactly contains, as you confirmed for example,
(06:00am - 03:00pm)

then this formula in cell B1 would return 6:00
=SUBSTITUTE(LEFT(A1,FIND(" ",A1)-3),"(","")

and this formula in cell C1 would return 3:00
=SUBSTITUTE(TRIM(RIGHT(A1,LEN(A1)-SEARCH("-",A1))),"pm)","")

If you really want a macro to do that, here is one which will put those values into B1 and C1 respectively, which you can modify (or not) for desired time format if you choose.

Code:
Sub test()
Dim strTime$
strTime = Range("A1").Text
With WorksheetFunction
Range("B1").Value = Trim(Mid(strTime, .Find("(", strTime) + 1, .Find("a", strTime) - .Find("(", strTime) - 1))
Range("C1").Value = Trim(Mid(strTime, .Find("-", strTime) + 1, .Find("p", strTime) - .Find("-", strTime) - 1))
End With
End Sub
 
Upvote 0
In addition, how would I format a display for a 24 hour clock setting. Meaning if the time shows 06:00pm and I want it to show 18:00. And visa versa, if it is showing 12:00pm, for it to display 12:00, instead of 00:00. I have an ending time function representing TIME(12,0,0). [For hour, minute and second], along with TIME(24,0,0), however, one of those function satisfies the 06:00pm to reflect 18:00 and the TIME(24,0,0) reflects the 12:000pm to be 12:00. How can I derive at a function that will satisfy both simoutaneously?
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

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