Compare data from 2 workbook sheets and inserting new/missing data [closed]












-1














I am very green to code so apologies 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, one has a list of my projects the other also lists these projects but is used for a different purpose, currently defined as "January_2019". Currently i manually enter new rows in the second workbook containing January_2019 and physically copy and paste the new projects names and numbers over from Projects workbook. 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?



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.



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:Projects.xls")
Set varSheetA = wbkA.Worksheets("Job_List")

strRangeToCheck = "A1:G500"
Debug.Print Now
varSheetA = Worksheets("Job_List").Range(strRangeToCheck)
varSheetB = Worksheets("January_2019").Range(strRangeToCheck)
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









share|improve this question







New contributor




Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as off-topic by Jamal Dec 29 '18 at 23:58


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Welcome to Code Review! I'm afraid our site is not the right fit for your question: we only answer questions about code that is working as intended, as explained in our help center. For help debugging code I would recommend asking at Stack Overflow, though be sure to read their How to ask page and How to debug small programs before asking.
    – Graham
    Dec 29 '18 at 21:12


















-1














I am very green to code so apologies 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, one has a list of my projects the other also lists these projects but is used for a different purpose, currently defined as "January_2019". Currently i manually enter new rows in the second workbook containing January_2019 and physically copy and paste the new projects names and numbers over from Projects workbook. 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?



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.



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:Projects.xls")
Set varSheetA = wbkA.Worksheets("Job_List")

strRangeToCheck = "A1:G500"
Debug.Print Now
varSheetA = Worksheets("Job_List").Range(strRangeToCheck)
varSheetB = Worksheets("January_2019").Range(strRangeToCheck)
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









share|improve this question







New contributor




Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as off-topic by Jamal Dec 29 '18 at 23:58


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Welcome to Code Review! I'm afraid our site is not the right fit for your question: we only answer questions about code that is working as intended, as explained in our help center. For help debugging code I would recommend asking at Stack Overflow, though be sure to read their How to ask page and How to debug small programs before asking.
    – Graham
    Dec 29 '18 at 21:12
















-1












-1








-1







I am very green to code so apologies 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, one has a list of my projects the other also lists these projects but is used for a different purpose, currently defined as "January_2019". Currently i manually enter new rows in the second workbook containing January_2019 and physically copy and paste the new projects names and numbers over from Projects workbook. 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?



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.



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:Projects.xls")
Set varSheetA = wbkA.Worksheets("Job_List")

strRangeToCheck = "A1:G500"
Debug.Print Now
varSheetA = Worksheets("Job_List").Range(strRangeToCheck)
varSheetB = Worksheets("January_2019").Range(strRangeToCheck)
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









share|improve this question







New contributor




Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am very green to code so apologies 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, one has a list of my projects the other also lists these projects but is used for a different purpose, currently defined as "January_2019". Currently i manually enter new rows in the second workbook containing January_2019 and physically copy and paste the new projects names and numbers over from Projects workbook. 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?



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.



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:Projects.xls")
Set varSheetA = wbkA.Worksheets("Job_List")

strRangeToCheck = "A1:G500"
Debug.Print Now
varSheetA = Worksheets("Job_List").Range(strRangeToCheck)
varSheetB = Worksheets("January_2019").Range(strRangeToCheck)
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






beginner






share|improve this question







New contributor




Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Dec 29 '18 at 17:55









Gary PS

1




1




New contributor




Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Gary PS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




closed as off-topic by Jamal Dec 29 '18 at 23:58


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Jamal Dec 29 '18 at 23:58


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.












  • Welcome to Code Review! I'm afraid our site is not the right fit for your question: we only answer questions about code that is working as intended, as explained in our help center. For help debugging code I would recommend asking at Stack Overflow, though be sure to read their How to ask page and How to debug small programs before asking.
    – Graham
    Dec 29 '18 at 21:12




















  • Welcome to Code Review! I'm afraid our site is not the right fit for your question: we only answer questions about code that is working as intended, as explained in our help center. For help debugging code I would recommend asking at Stack Overflow, though be sure to read their How to ask page and How to debug small programs before asking.
    – Graham
    Dec 29 '18 at 21:12


















Welcome to Code Review! I'm afraid our site is not the right fit for your question: we only answer questions about code that is working as intended, as explained in our help center. For help debugging code I would recommend asking at Stack Overflow, though be sure to read their How to ask page and How to debug small programs before asking.
– Graham
Dec 29 '18 at 21:12






Welcome to Code Review! I'm afraid our site is not the right fit for your question: we only answer questions about code that is working as intended, as explained in our help center. For help debugging code I would recommend asking at Stack Overflow, though be sure to read their How to ask page and How to debug small programs before asking.
– Graham
Dec 29 '18 at 21:12












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?