View Full Version : Solved: How to write format code in VBA?
genracela
05-06-2010, 09:46 PM
I created a vlookup VBA code and it works:
lRow = Range("A:A").Find(what:="*", LookIn:=xlValues, SearchOrder:=xlByRows, _
searchdirection:=xlPrevious).Row
Range("E2:E" & lRow).Formula = "=vlookup(C2,etc!A:B,2,False)"
End With
My problem is, the cell returned 40262 for 25-Mar-10.
How will I add formatting on my code?
Try changing the number format of the cells to a date.
genracela
05-06-2010, 10:09 PM
actually i want to incorporate the formatting in my VBA code so all I have to do is to run the code.
I know it's kinda like format(xxx,dd-mm-yy,xxx,xxx)
I just don't know what expressions or symbols or data to put on those xxx.
Actually I think you want .NumberFormat. Something like:
'...preceeding code...
lRow = Range("A:A").Find(what:="*", LookIn:=xlValues, SearchOrder:=xlByRows, _
searchdirection:=xlPrevious).Row
With Range("E2:E" & lRow)
.NumberFormat = "d-mmm-yy"
.Formula = "=vlookup(C2,etc!A:B,2,False)"
End With
End With
An easy way to get the correct arg is to open a new wb and record a quick macro, changing the active cell's format to how you want the date to display.
genracela
05-06-2010, 10:39 PM
Thanks GTO!:bow:
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.