Hi All
I am very green to VBA so apologies for the massive gaps in my knowledge or if this has already been answered but I am struggling to find a code that covers what i would like to do.
So i have to two workbooks, WB1 has a list of my projects (address and job database which contains the sheet "Job_list") the other (WB2) also lists these projects but is used for a different purpose, currently defined as "Sheet15". Currently i manually enter new rows in the second workbook containing sheet15 and physically copy and paste the new projects names and numbers over from the "job_list". Simple enough but wondered if this could be automated with VBA.
I need to bring in the project number I allocate (column A in WB1) and paste it in column B in WB2. As well as and the Name (column F in WB1) and paste into column C in WB2.
Can the data set be compared and rows inserted to suit the new data? Is there a way to only check data added since the last time the macro was run?
I have had a go at the code based on what i have found but all help would be appreciated as i am getting an runtime error 9 for the "else" part and I am just a tad overwhelmed by how to solve it. If i need to post somewhere else then guidance would be appreciated.
Thanks in advance.
I am very green to VBA so apologies for the massive gaps in my knowledge or if this has already been answered but I am struggling to find a code that covers what i would like to do.
So i have to two workbooks, WB1 has a list of my projects (address and job database which contains the sheet "Job_list") the other (WB2) also lists these projects but is used for a different purpose, currently defined as "Sheet15". Currently i manually enter new rows in the second workbook containing sheet15 and physically copy and paste the new projects names and numbers over from the "job_list". Simple enough but wondered if this could be automated with VBA.
I need to bring in the project number I allocate (column A in WB1) and paste it in column B in WB2. As well as and the Name (column F in WB1) and paste into column C in WB2.
Can the data set be compared and rows inserted to suit the new data? Is there a way to only check data added since the last time the macro was run?
I have had a go at the code based on what i have found but all help would be appreciated as i am getting an runtime error 9 for the "else" part and I am just a tad overwhelmed by how to solve it. If i need to post somewhere else then guidance would be appreciated.
Thanks in advance.
Code:
Option Explicit
Sub InsertJobs()
Dim wbkA As Variant
Dim varSheetA As Variant
Dim varSheetB As Variant
Dim strRangeToCheck As String
Dim iRow As Long
Dim iCol As Long
Set wbkA = Workbooks.Open(Filename:="P:\Address_&_Job_Database.xls")
Set varSheetA = wbkA.Worksheets("Job_List") ' or whatever sheet you need
strRangeToCheck = "A1:G500"
' If you know the data will only be in a smaller range, reduce the size of the ranges above.
Debug.Print Now
varSheetA.Range (strRangeToCheck)
varSheetB = Worksheets(Sheet15).Range(strRangeToCheck) ' or whatever your other sheet is.
Debug.Print Now
For iRow = LBound(varSheetA, 1) To UBound(varSheetA, 1)
For iCol = LBound(varSheetA, 2) To UBound(varSheetA, 2)
If varSheetA(iRow, iCol) = varSheetB(iRow, iCol) Then
' Cells are identical.
' Do nothing.
Else
' Cells are different.
Sheets(varSheetA).Range("A" & "F").Copy Destination:=Sheets("January_2019").Range("B" & "C")
Dim i As Long, r1 As Range, r2 As Range
For i = 4 To 500
Set r1 = Range("A" & i)
Set r2 = Range("B" & i & ":C" & i)
Next i
End If
Next iCol
Next iRow
End Sub