Left Function in VB

Vampy99

New Member
Joined
Jul 13, 2011
Messages
42
Hi,

In column A I have a number of times in number format e.g 47715.XXXXX

I only want to select the first 5 characters so I can then convert this to a date without having the time (it messes up my pivot table!)

I then want these to be pasted in column B.

Does anyone know the syntax for this in VB?

I'm still new to this language & am trying to learn as much as I can!

Thank you for any help in advance.

Luke
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You can do that with a formula

Excel Workbook
AB
147715.1234547715
Sheet2


Thanks for the response VoG. I would usually use =LEFT(A1,5) but I've read that there is a VB function for this so wanted to give that a try? I've just been unable to find the syntax that gives me what I want

Thanks,

Luke
 
Upvote 0
The VB function is also Left (or Int would be better here, as Peter suggested).
 
Upvote 0
Ok, so is this the best way to do it? Doing the left formula & copying the formula to the bottom row?

Code:
Range("B2").Formula = "=INT(A2)"
Range("B2").Copy
Range("B3:B" & NumRows & "").PasteSpecial

"NumRows" is a variable which lets me know the last number of the last row.
 
Upvote 0
Or if you don't want to keep the formulas

Code:
With Range("B2:B" & NumRows)
    .Formula = "=INT(A2)"
    .Value = .Value
End With
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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