Need help in changing date from dd/mm/yyyy to dd-mmm-yyyy from Macro

amandeep08

Board Regular
Joined
Mar 20, 2011
Messages
130
Office Version
  1. 365
I have one Macro but the date format is coming as dd/mm/yyyy. I want to change the same to dd-mmm-yyyy.
Below is the coding:


Dim i As Double
Dim j As Double
Dim wholeLine As String

Dim aWF As WorksheetFunction
Set aWF = Application.WorksheetFunction

Application.ScreenUpdating = True

ThisWorkbook.Worksheets("menu").Range("D10").Value = "Current Record"
ThisWorkbook.Worksheets("menu").Range("G10").Value = 0

i = startRow

Do While i <= noOfRows
j = 1
ThisWorkbook.Worksheets("menu").Range("G10").Value = i
If i > startRow Then
wholeLine = wholeLine & vbNewLine
End If

Do While j <= noOfCols
If j > 1 Then
wholeLine = wholeLine & "^"
End If
If IsDate(Trim(aWF.Clean(SourceWB.Worksheets(sheetName).Cells(i, j)))) Then
wholeLine = wholeLine & makeString(Day(Trim(aWF.Clean(SourceWB.Worksheets(sheetName).Cells(i, j)))), 2, "0", True) _
& "/" & makeString(Month(Trim(aWF.Clean(SourceWB.Worksheets(sheetName).Cells(i, j)))), 2, "0", True) _
& "/" & Year(Trim(aWF.Clean(SourceWB.Worksheets(sheetName).Cells(i, j))))
Else
wholeLine = wholeLine & Trim(aWF.Clean(SourceWB.Worksheets(sheetName).Cells(i, j)))
End If
j = j + 1
Loop
i = i + 1
Loop
Call ExportToTextFile(outputFileName, wholeLine, False)

MsgBox "File Conversion Successful"

errorHandler:
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description
Exit Sub
End If

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this out, adjust the column letter or letters if necessary

VBA Code:
Sub ChangeDateFormat()
Columns("G").NumberFormat = "dd-mm-yyyy"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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