Hi Guy's, I am fairly close with this one and require you great guy's to correct me
I am trying open an excel file on sheet 3 and retrieve data from the last row on Columns A, B and F
all looks ok to me apart from:
I can't seem to open the file on sheet 3
therefore strings strColA, strColB and strColF are not returning the correct data
Have i got this correct apart from not opening on Sheet 3 ?
Code:
Dim xlApp As Object Dim xlWbk As Object
Dim xlWsh As Object
Dim strPath As String, strFile As String, strColA As String, strColB As String, strColF As String
Dim iSheet As Integer, i As Integer, intLR As Integer, iRow As Integer
Dim varResult As Variant
iSheet = "3"
strPath = "T:\DMT Ltd\Fuel Price Sheets\"
strFile = "Fuel Prices.xlsx"
Set xlApp = CreateObject("Excel.Application")
Set xlWbk = xlApp.Workbooks.Open(strPath & strFile)
Set xlWsh = xlWbk.Worksheets(iSheet)
xlApp.Visible = True
With xlWsh
intLR = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 1 To intLR
strColF = xlWsh.Range("F" & i).Value
strColA = xlWsh.Range("A" & i).Value
strColB = xlWsh.Range("B" & i).Value
Exit For
Next i
End With
Debug.Print strColA
Debug.Print strColB
Debug.Print strColF
MsgBox ("the data on last rows of Column A, B and F is:" & vbCrLf & vbCrLf & _
strColA & vbCrLf & _
strColB & vbCrLf & _
strColF)
'Application.FollowHyperlink strPath & strFile
Set xlWsh = Nothing
Set xlWbk = Nothing
Set xlApp = Nothing