ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Excel changing date format after VB has run (https://www.excelbanter.com/excel-worksheet-functions/252433-excel-changing-date-format-after-vbulletin-has-run.html)

Richhall[_2_]

Excel changing date format after VB has run
 
Hi

I have a sheet 1 with a combo box and a blank field. When something
is selected from the combo box a date gets populated in the blank
field. The date is custom formatted as mmm-yyyy.

On sheet 2 I have a table with the options in the drop down box and a
date next to them. When a selection is done, the code does a VLOOKUP
and populates the data in Sheet 1 in the blank field. Dates are also
mmm-yyyy in the Sheet 2.

The problem is, say the date in Sheet 2 is 01/12/2010 displayed as
Dec-2010. When it is put into sheet w, it flips it to 12/01/2010 so
says Jan-2010. Any idea why this is happening please?

Code Below - VersionRange is a named Range ($C$4:$F$56) in Sheet 2

Dim boxdate
Dim VerValue
Dim VerRange
Dim ws As Worksheet

Set ws = Worksheets("Sheet 2")
VerValue = Combo1.Text
VerRange = ws.Range("VersionRange")

If VerValue = "" Then
boxdate= ""
Else: boxdate = Application.WorksheetFunction.VLookup(VerValue,
VerRange, 2)
End If

Range("A19").Select
ActiveCell.FormulaR1C1 = boxdate


Thank you

Rich

Richhall[_2_]

Excel changing date format after VB has run
 
Also, I have tried changing the fields to text but then the VLOOKUP
wont work.

Dave Peterson

Excel changing date format after VB has run
 
I'd try:

with Range("A19")
'an unambiguous date format for testing
.numberformat = "mmmm dd, yyyy"
.value = clng(boxdate)
end with


Richhall wrote:

Hi

I have a sheet 1 with a combo box and a blank field. When something
is selected from the combo box a date gets populated in the blank
field. The date is custom formatted as mmm-yyyy.

On sheet 2 I have a table with the options in the drop down box and a
date next to them. When a selection is done, the code does a VLOOKUP
and populates the data in Sheet 1 in the blank field. Dates are also
mmm-yyyy in the Sheet 2.

The problem is, say the date in Sheet 2 is 01/12/2010 displayed as
Dec-2010. When it is put into sheet w, it flips it to 12/01/2010 so
says Jan-2010. Any idea why this is happening please?

Code Below - VersionRange is a named Range ($C$4:$F$56) in Sheet 2

Dim boxdate
Dim VerValue
Dim VerRange
Dim ws As Worksheet

Set ws = Worksheets("Sheet 2")
VerValue = Combo1.Text
VerRange = ws.Range("VersionRange")

If VerValue = "" Then
boxdate= ""
Else: boxdate = Application.WorksheetFunction.VLookup(VerValue,
VerRange, 2)
End If

Range("A19").Select
ActiveCell.FormulaR1C1 = boxdate

Thank you

Rich


--

Dave Peterson

Richhall[_2_]

Excel changing date format after VB has run
 
Seems it was something to do with the VLOOKUP, dates are fine now as I
added:

Set VerRange = Worksheets("Sheet 2").Range("VersionRange")

Everything seemed to start working ok.

Thanks anyway. Eventually I just added the VLOOKUP into the cell
using an Admin sheet with the VerValue set in a cell there.

Cheers

Rich


All times are GMT +1. The time now is 03:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com