I have written VBA to do the following:
1) Find a workbook named after the House Name in column A.
2) Copy and paste the contents of columns A-P to the workbook. Data should be pasted in cell B5 onwards.
The problem I have is that in my spreadsheet a House Name can have multiple rows of data. I need all the rows to be copied to the individual workbooks. Would it be possible to:
1) Filter column A for each of the House Names and paste all filtered results to the individual workbooks. . Data should be pasted in cell B5 onwards.
2) Paste values only?
I have attached a screenshot of the dataset (all records are fictional). I can provide a copy of the spreadsheet if this is helpful.
The VBA I currently have is:
Sub CopyPasteData()
Dim previousAlertsFlag As Boolean
Dim masterWB As Workbook
Dim masterWS As Worksheet
Dim destWB As Workbook
Dim destWS As Worksheet
Dim lastRow As Long
Dim filepath As String
Dim fullpath As String
Dim r As Integer
Set masterWB = ThisWorkbook
Set masterWS = masterWB.Worksheets("Sheet1")
lastRow = masterWS.Cells(masterWS.Rows.Count, "A").End(xlUp).Row
filepath = "C:\Users\SAHU11\OneDrive - NHS\Desktop\test\"
For r = 2 To lastRow
User = masterWS.Cells(r, 1).Value
fullpath = filepath & User
Set destWB = Workbooks.Open(fullpath)
Set destWS = destWB.Sheets("Sheet1")
masterWS.Cells(r, 2).Resize(, 15).Copy destWS.Cells(5, 2)
destWB.Close SaveChanges:=True
Next r
End Sub
1) Find a workbook named after the House Name in column A.
2) Copy and paste the contents of columns A-P to the workbook. Data should be pasted in cell B5 onwards.
The problem I have is that in my spreadsheet a House Name can have multiple rows of data. I need all the rows to be copied to the individual workbooks. Would it be possible to:
1) Filter column A for each of the House Names and paste all filtered results to the individual workbooks. . Data should be pasted in cell B5 onwards.
2) Paste values only?
I have attached a screenshot of the dataset (all records are fictional). I can provide a copy of the spreadsheet if this is helpful.
The VBA I currently have is:
Sub CopyPasteData()
Dim previousAlertsFlag As Boolean
Dim masterWB As Workbook
Dim masterWS As Worksheet
Dim destWB As Workbook
Dim destWS As Worksheet
Dim lastRow As Long
Dim filepath As String
Dim fullpath As String
Dim r As Integer
Set masterWB = ThisWorkbook
Set masterWS = masterWB.Worksheets("Sheet1")
lastRow = masterWS.Cells(masterWS.Rows.Count, "A").End(xlUp).Row
filepath = "C:\Users\SAHU11\OneDrive - NHS\Desktop\test\"
For r = 2 To lastRow
User = masterWS.Cells(r, 1).Value
fullpath = filepath & User
Set destWB = Workbooks.Open(fullpath)
Set destWS = destWB.Sheets("Sheet1")
masterWS.Cells(r, 2).Resize(, 15).Copy destWS.Cells(5, 2)
destWB.Close SaveChanges:=True
Next r
End Sub