Telmo Cascalheira
Telmo Cascalheira

Reputation: 11

Bug with dates, set wrong on or the other pair

I am quite new with VBa and i am facing a problem right now. I have in a Multipage, with 2 pages, a frame in each, inside each frame i have to Date picker for Initial date and Final date, named DTPicker1Li, DTPicker2LI, DTPicker3LI and DTPicker4LI. The form in whic they are is frmInserirImpLI.

for getting the values

 DInicioILI = frmInserirImpLI.DTPicker1LI.Value
 DFimILI = frmInserirImpLI.DTPicker2LI.Value
 DInicioLImp = frmInserirImpLI.DTPicker3LI.Value
 DFimLImp = frmInserirImpLI.DTPicker4LI.Value

for writing in excel cells i have

 Range("H" & linhaAEscreverLI) = DInicioILI
 Range("I" & linhaAEscreverLI) = DFimILI
 Range("O" & linhaAEscreverLI) = DInicioLImp
 Range("P" & linhaAEscreverLI) = DFimLImp

The problem is it only passes the correct dates for 2 of the cells. or it write in columns H and I the correct dates and then in columns O and P appears: 00-01-1900 or if the dates appears correctly in columns O and P it will appear in columns H and I: 12:00:00 AM what am i doing wrong?

Thanks in advance

Upvotes: 1

Views: 41

Answers (1)

R3uK
R3uK

Reputation: 14547

Just add formatting after setting the value :

Range("H" & linhaAEscreverLI) = DInicioILI
Range("H" & linhaAEscreverLI).NumberFormat = "dd/mm/yy"

Upvotes: 1

Related Questions