Hello, I'm trying to set up an import routine to run through a workbook with multiple worksheets and ranges for import into one table. The import will always start with Column/row A5. I'm at the moment just trying to cycle through each worksheet to ensure I'm capturing the last populated cell, but the routine I'm using below keeps giving the same last cell across all worksheets (when I know the last cell is different). Once the routine runs the workbook doesn't want to open, it flashes briefly on the screen, like its hidden or locked, is it something to do with how I'm calling excel, closing it...
Your assistance is appreciated: 1) why the last cell doesn't update with the active worksheet, 2) why workbook doesn't want to display after routine runs.
Code:
Sub ImportExcel()
Dim Range As Excel.Range
Dim excelapp As New Excel.Application
Dim excelbook As New Excel.Workbook
Dim excelsheet As New Excel.Worksheet
Dim intNoOfSheets As Integer, intCounter As Integer
Dim strFilePath As String
Dim LastColumn As Long
Dim LastRow As Long
strFilePath = "g:\Desktop\Summary Scoring for Lab Equip List for fiscals 2014-16.xls"
'strFilePath = "g:\Desktop\Service-Academic Split.xlsx"
Set excelbook = excelapp.Workbooks.Open(strFilePath)
intNoOfSheets = excelbook.Worksheets.Count
For intCounter = 1 To intNoOfSheets
excelbook.Worksheets(intCounter).Activate
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
MsgBox excelbook.Worksheets(intCounter).Name & "!A5:" & Cells(LastRow, LastColumn).Address
Next
excelbook.Close
excelapp.Quit
Set excelapp = Nothing
End Sub