Forum Discussion
Copying Master Sheet Rows to Sheets Based on Column - Assistance
- Sep 20, 2023
Does the code in the attached file return the intended result?
Sub MoveRowsToActiveBrokers() Dim sourceSheet As Worksheet Dim targetSheet As Worksheet Dim lastRow, lastRow2 As Long Dim i As Long Set sourceSheet = ThisWorkbook.Worksheets("Master Contact List") Set targetSheet = ThisWorkbook.Worksheets("Active Brokers") lastRow = sourceSheet.Range("B" & Rows.Count).End(xlUp).Row For i = 3 To lastRow If sourceSheet.Cells(i, 2).Value = "Broker" Then lastRow2 = targetSheet.Range("B" & Rows.Count).End(xlUp).Row sourceSheet.Rows(i).Copy Destination:=targetSheet.Rows(lastRow2 + 1) End If Next End Sub
Does the code in the attached file return the intended result?
Sub MoveRowsToActiveBrokers()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow, lastRow2 As Long
Dim i As Long
Set sourceSheet = ThisWorkbook.Worksheets("Master Contact List")
Set targetSheet = ThisWorkbook.Worksheets("Active Brokers")
lastRow = sourceSheet.Range("B" & Rows.Count).End(xlUp).Row
For i = 3 To lastRow
If sourceSheet.Cells(i, 2).Value = "Broker" Then
lastRow2 = targetSheet.Range("B" & Rows.Count).End(xlUp).Row
sourceSheet.Rows(i).Copy Destination:=targetSheet.Rows(lastRow2 + 1)
End If
Next
End Sub
- OliverScheurichSep 21, 2023Gold Contributor
I've added a line of descriptions in row 2 of the "Active Brokers" sheet and the code returns the intended result. Does it work for you in the attached file as well? Otherwise can you attach a sample file without sensitive data?
- LDLogDogSep 21, 2023Copper Contributor
For some reason it is not letting me upload a similar XLSM file so I had to provide a picture of how the rows are formatted, and the macro is exactly as below. If you know how to upload it let me know and I can upload the file for you to take a look. Thank you!
- OliverScheurichSep 21, 2023Gold Contributor
You can send a file by private message. If you select my user icon you can choose messages.
Then you can write a New Message.
Within the new message you can browse, select and attach a file.