Hello there! I'm hoping you can help.
I'm having trouble figuring out how to capture data input by users into WB1 into a master workbook (WB2), without allowing multiple rows of data be input for the same policy number. I'd like it to instead override the existing data if it's for the same policy number.
I have code to insert the new row of data into the master workbook from the user's workbook. But I don't know how to avoid duplicates or multiple lines with different data for the same policy number.
Each user has a workbook on their desktop that they input data into, we'll call WB1
When they click on the Insert macro, it copies WB1, Sheet 6, Row 3, and inserts it at the bottom into WB2 Sheet 1.
One item they input is a policy number, which is in WB1, Sheet6, Range("C3").
I need to search column B in WB2 for this value.
If found, I need to copy WB1, Sheet6, Row 3, and paste it over the row with the matching number, in WB2, Sheet1.
If not found, I need to copy WB1, Sheet6, Row 3, and insert it under the last entry in WB2, Sheet1.
Also, instead of calling the user's WB1 "ThisWorkbook", I'd like to call it by the name, but it differs per user and is on their desktop. It always starts with the same word "Pfd" though. I thought using "Pfd*" would work, but it doesn't.
The code I have to insert the data is below. Any help would be greatly appreciated!
I'm having trouble figuring out how to capture data input by users into WB1 into a master workbook (WB2), without allowing multiple rows of data be input for the same policy number. I'd like it to instead override the existing data if it's for the same policy number.
I have code to insert the new row of data into the master workbook from the user's workbook. But I don't know how to avoid duplicates or multiple lines with different data for the same policy number.
Each user has a workbook on their desktop that they input data into, we'll call WB1
When they click on the Insert macro, it copies WB1, Sheet 6, Row 3, and inserts it at the bottom into WB2 Sheet 1.
One item they input is a policy number, which is in WB1, Sheet6, Range("C3").
I need to search column B in WB2 for this value.
If found, I need to copy WB1, Sheet6, Row 3, and paste it over the row with the matching number, in WB2, Sheet1.
If not found, I need to copy WB1, Sheet6, Row 3, and insert it under the last entry in WB2, Sheet1.
Also, instead of calling the user's WB1 "ThisWorkbook", I'd like to call it by the name, but it differs per user and is on their desktop. It always starts with the same word "Pfd" though. I thought using "Pfd*" would work, but it doesn't.
The code I have to insert the data is below. Any help would be greatly appreciated!
VBA Code:
Sub Insert()
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
Workbooks.Open "network drive path for WB2"
Set wsCopy = ThisWorkbook.Worksheets("Sheet6") ' User's workbook WB1
Set wsDest = Workbooks("Credit Spreadsheet.xlsx").Worksheets("Sheet1") 'Master workbook WB2
IDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
wsCopy.Range("3:3").Copy _
wsDest.Range("A" & lDestLastRow)
Workbooks("Credit Spreadsheet.xlsx").Close SaveChanges:=True
End Sub
Last edited by a moderator: