Hi Guyt's, where am i going wrong here please ?
I am trying to update target file and sheet on the next avalable row in column A
from a selected page from source file, so immediate window is giving me correct rows and amout of data but not transferring to target file and sheet
also when i quit and set all instanaces to nothing, the sheets are wiped clean (have back ups)
hence commeneted out
Code:
Dim i As Integer, iAddRecs As Integer, iRecsNext As Integer, iNum As Integer, x As Integer, intLR As Integer, intLRAll As Integer, intLR2 As Integer, iNextRow As IntegerDim rs As DAO.Recordset
Dim strCode As String, strResult() As String, strNum As String, strFind As String, strNewRec As String, strOrgCode As String
Dim xlAP As Object, xlSourceWB As EXCEL.Workbook, xlTargetWB As EXCEL.Workbook, xlSourceSHT As EXCEL.Worksheet, xlTargetSHT As EXCEL.Worksheet, fndRng As EXCEL.Range
Dim xlAP2 As Object, xlWB2 As EXCEL.Workbook, xlSHT3 As EXCEL.Worksheet, fndRng2 As EXCEL.Range, rngTo As Range, rngFrom As Range
Dim xl As Object, xl2 As Object
Dim strPath As String, strSourceFile As String, strTargetFile As String, strData As String
Dim intPage As Integer, iSourceLR As Integer, iTargetLR As Integer, iTargetNR As Integer
Dim varPage As Variant
varPage = InputBox("Enter Page A-Z ?" & vbCrLf & vbCrLf & _
"Leave Blank To Abort", "ENTER PAGE")
Select Case varPage
Case Is = ""
Exit Sub
Case Else
strPath = "C:\Users\davem\Desktop\"
strTargetFile = "Target File.xlsx"
strSourceFile = "Source File.xlsx"
Set xlAP = CreateObject("Excel.Application")
Set xlAP2 = CreateObject("Excel.Application")
Set xlSourceWB = GetObject(strPath & strSourceFile)
Set xlTargetWB = GetObject(strPath & strTargetFile)
Set xlSourceSHT = xlSourceWB.Worksheets(varPage)
Set xlTargetSHT = xlTargetWB.Worksheets("Customers")
xlAP.Visible = False
xlAP2.Visible = False
With xlTargetSHT
iSourceLR = xlSourceSHT.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row ' Find Last Row With Data
iTargetLR = xlTargetSHT.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row ' Find Last Row With Data
iTargetNR = iTargetLR + 1 ' Next Row To Append Data
Debug.Print xlSourceSHT.Name & " - " & iSourceLR & " Total Rows" & vbCrLf & vbCrLf & _
xlTargetSHT.Name & " - " & "To Go From Row " & iTargetNR
For i = 1 To iSourceLR
xlTargetSHT.Cells(iTargetNR, 1) = xlSourceSHT.Cells(2 + iSourceLR, 1)
iSourceLR = iSourceLR + 1
Next i
End With
xlSourceWB.Close
'xlTargetWB.Close True
' Set xlTargetSHT = Nothing
' Set xlSourceSHT = Nothing
' Set xlSourceWB = Nothing
' Set xlTargetWB = Nothing
' xlAP.Quit
' xlAP2.Quit
' Set xlAP = Nothing
' Set xlAP2 = Nothing