Hi all,
I can get the code below to work as an Excel Macro, but I'm at a loss with trying to do the same from Access VBA by using Excel automation (it's part of an import procedure I'm working on). Can anyone help?
I'd like to just use Access VBA and don't want to use any external files (such as a .bas file that I could call from Access) if possible.
Here's the code in Excel:
Is there an Access VBA equivalent? I have the following code to start off, but am stuck as to how to type up the For...Next part.
I can get the code below to work as an Excel Macro, but I'm at a loss with trying to do the same from Access VBA by using Excel automation (it's part of an import procedure I'm working on). Can anyone help?
I'd like to just use Access VBA and don't want to use any external files (such as a .bas file that I could call from Access) if possible.
Here's the code in Excel:
Code:
' Code modified slightly from Hiker95's (forum member on MrExcel.com) code
Dim LR As Long, a As Long
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 1).End(xlUp).Row
For a = LR To 2 Step -1
Cells(a, 1).Select
If IsDate(Cells(a, 1)) = False Then
Cells(a, 1).EntireRow.Delete
End If
Next a
Application.ScreenUpdating = True
Is there an Access VBA equivalent? I have the following code to start off, but am stuck as to how to type up the For...Next part.
Code:
Private Sub cmdImportExcel_Click()
Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
Dim xlWorkbook As Excel.Workbook
On Error Resume Next
'If Excel is already open, get a handle to
'the existing instance.
Set xlApp = GetObject(, "Excel.Application")
'Test for an error condition.
If Err <> 0 Then
'Excel is not currently open, create an
'instance.
Set xlApp = CreateObject("Excel.Application")
End If
Set xlWorkbook = xlApp.Workbooks.Open("c:\DatesToImport.xls", 0, False)
Set xlSheet = xlApp.Worksheets("Sheet1")
xlApp.DisplayAlerts = False
xlSheet.Range("A2:A" & xlSheet.Cells.SpecialCells(xlCellTypeLastCell).Row).Select
'This space is where I need to type in the lines of
'code to loop through Column A to find non date fields
'and delete them when found.
End Sub