PROBLEM DATE IN VBA

roykana

Active Member
Joined
Mar 8, 2018
Messages
311
Office Version
  1. 2010
Platform
  1. Windows
Dear master all,


I have a problem in vba, namely the date results from the vba process do not match in column C
and I use the date with the formula in column D so that I can compare the results in column e.
The results in column e should be the same. Please solve my problem.
this my link : PROBLEM DATE IN VBA.xlsm
file

thanks
roykana
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Dear master all,


I have a problem in vba, namely the date results from the vba process do not match in column C
and I use the date with the formula in column D so that I can compare the results in column e.
The results in column e should be the same. Please solve my problem.
this my link : PROBLEM DATE IN VBA.xlsm
file


thanks
roykana
I never click on links in this forum. Would you please post your code here in the forum.
 
Upvote 0
VBA Code:
Sub Get_Data_From_File()
    Dim L As Integer
    Dim LastRow As Long
    Dim LastColumn As Long
    Application.ScreenUpdating = False
        LastRow = Range("A1").SpecialCells(xlCellTypeLastCell).Row
        LastColumn = Range("A1").SpecialCells(xlCellTypeLastCell).Column

    For L = 2 To LastRow
    Cells(L, 3).Value = DateSerial(Mid(Cells(L, 2), 11, 4), Mid(Cells(L, 2), 4, 2), Mid(Cells(L, 2), 1, 2))
    Next L
    
    Application.ScreenUpdating = True
    End Sub
 
Upvote 0
In Excel, you correctly write:

=DATE(MID(B2,7,4),MID(B2,4,2),MID(B2,1,2))

In VBA, you incorrectly write:

Cells(L, 3).Value = DateSerial(Mid(Cells(L, 2), 11, 4), Mid(Cells(L, 2), 4, 2), Mid(Cells(L, 2), 1, 2))
 
Upvote 0
Solution
In Excel, you correctly write:

=DATE(MID(B2,7,4),MID(B2,4,2),MID(B2,1,2))

In VBA, you incorrectly write:

Cells(L, 3).Value = DateSerial(Mid(Cells(L, 2), 11, 4), Mid(Cells(L, 2), 4, 2), Mid(Cells(L, 2), 1, 2))
ok thanks
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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