Howdy.
Hopefully this will prove to be a simple question with a simple answer. I am currently using VBA to format an Excel spreadsheet from an Access module before transferring it to a table in the database. I am writing a loop to format dates from YYYYMMDD to MM/DD/YYYY. While I have the code for re-arranging the dates written, I am having trouble finding a good way to loop through the cells in the column. I need to loop from C:2 to the end of the column. Here is my loop code:
The problem area of the loop is outlined in ***. The way it is currently written, I would like c to equal the cell that's being formatted.
Thanks in advance for the help!
Hopefully this will prove to be a simple question with a simple answer. I am currently using VBA to format an Excel spreadsheet from an Access module before transferring it to a table in the database. I am writing a loop to format dates from YYYYMMDD to MM/DD/YYYY. While I have the code for re-arranging the dates written, I am having trouble finding a good way to loop through the cells in the column. I need to loop from C:2 to the end of the column. Here is my loop code:
Code:
Option Compare Database
Sub TestMacro()
Dim xlsApp As Object
Dim xlsFileName As String
Dim xlsFilePath As String
Dim year As String
Dim day As String
Dim month As String
xlsFilePath = ***filepath name***
xlsFileName = ***filename***
Set xlsApp = GetObject(xlsFilePath & xlsFileName)
xlsApp.Application.Visible = True
xlsApp.Parent.Windows(1).Visible = True
xlsApp.ActiveSheet.Cells(1, 1) = "UNIT"
xlsApp.ActiveSheet.Cells(1, 2) = "SOURCE"
xlsApp.ActiveSheet.Cells(1, 3) = "DATE"
xlsApp.ActiveSheet.Cells(1, 4) = "BBCS"
xlsApp.ActiveSheet.Cells(1, 5) = "PROD"
xlsApp.ActiveSheet.Cells(1, 6) = "STATUS"
xlsApp.ActiveSheet.Cells(1, 7) = "DISP"
xlsApp.ActiveSheet.Cells(1, 8) = "LTD"
xlsApp.ActiveSheet.Cells(1, 9) = "SPEC"
'**************
For Each c In ***
If c <> "DATE" Then
day = Right(c, 2)
month = Mid(c, 5, 2)
year = Left(c, 4)
If c <> Empty And c <> "DATE" Then
c = month & "/" & day & "/" & year
End If
End If
Next c
'***************
xlsApp.Application.Save
xlsApp.Application.Quit
DoCmd.TransferSpreadsheet transfertype:=acImport, SpreadsheetType:=acSpreadsheetTypeExcel97, _
tableName:="DailyTest", fileName:=xlsFilePath & xlsFileName, hasFieldNames:=True
End Sub
The problem area of the loop is outlined in ***. The way it is currently written, I would like c to equal the cell that's being formatted.
Thanks in advance for the help!