How can I delete the rows below the last cell that contains data. I am not too familiar with excel VBA.
I am doing the following in my Access VBA currently to import the excel data into Access table.
Thankyou.
Dim exApp As Excel.Application
Dim ws As Excel.Worksheet
On Error GoTo errExportToExcel
Set exApp = CreateObject("Excel.Application"
exApp.Workbooks.Open "C:\Hospital.xls"
exApp.Application.Visible = True
exApp.Application.ActiveWorkbook.Activate
Set ws = exApp.Worksheets("UPLOAD"
GoToLastCell ws
' Import the spreadsheet file
DoCmd.TransferSpreadsheet acImport, nSpreadSheetType, "SPECTRUM_CALCULATION", _
cFileName, Me!ChkBox_FieldNames
Set exApp = Nothing
errExportToExcel:
Select Case Err.Number
Case 3010
MsgBox "Hospital.xls file is already open. Close file and try again.", vbOKOnly
Exit Sub
Case Else
MsgBox Err.Description, vbOKOnly
DoCmd.Hourglass False
Exit Sub
End Select
Sub GoToLastCell(ws As Worksheet)
ws.Select
If Range("A1"
.SpecialCells(xlLastCell).Value = "" Then
Cells(Cells.Find("*", _
ActiveCell.SpecialCells(xlLastCell), _
, , xlByRows, xlPrevious).Row, _
Cells.Find("*", _
ActiveCell.SpecialCells(xlLastCell), _
, , xlByColumns, xlPrevious).Column).Select
Else
Range("A1"
.SpecialCells(xlLastCell).Select
End If
End Sub
I am doing the following in my Access VBA currently to import the excel data into Access table.
Thankyou.
Dim exApp As Excel.Application
Dim ws As Excel.Worksheet
On Error GoTo errExportToExcel
Set exApp = CreateObject("Excel.Application"
exApp.Workbooks.Open "C:\Hospital.xls"
exApp.Application.Visible = True
exApp.Application.ActiveWorkbook.Activate
Set ws = exApp.Worksheets("UPLOAD"
GoToLastCell ws
' Import the spreadsheet file
DoCmd.TransferSpreadsheet acImport, nSpreadSheetType, "SPECTRUM_CALCULATION", _
cFileName, Me!ChkBox_FieldNames
Set exApp = Nothing
errExportToExcel:
Select Case Err.Number
Case 3010
MsgBox "Hospital.xls file is already open. Close file and try again.", vbOKOnly
Exit Sub
Case Else
MsgBox Err.Description, vbOKOnly
DoCmd.Hourglass False
Exit Sub
End Select
Sub GoToLastCell(ws As Worksheet)
ws.Select
If Range("A1"
Cells(Cells.Find("*", _
ActiveCell.SpecialCells(xlLastCell), _
, , xlByRows, xlPrevious).Row, _
Cells.Find("*", _
ActiveCell.SpecialCells(xlLastCell), _
, , xlByColumns, xlPrevious).Column).Select
Else
Range("A1"
End If
End Sub