Jyotirmaya
Board Regular
- Joined
- Dec 2, 2015
- Messages
- 205
- Office Version
- 2019
- Platform
- Windows
I am using the below code to copy data from a sheet to different sheets if the sheet name matches with text of column E
I have data in RAW DATA sheet and I am copying data from this sheet to other by using this macro. I have data till column H in RAW DATA sheet, now in a new column added for example if in column H Text is there as "ABC" in any row then I want that row shouldn't be copied to other sheets & it should be copied to sheet name "ABC" instead of the sheet name mentioned in column E, for this what should be the change in the code ??
VBA Code:
Sub CopyToSheets()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim lastrow As Long
Dim lastrow2 As Long
Dim rownum As Long
Dim ws2name As String
Set ws = Sheets("RAW DATA")
lastrow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row
For rownum = 2 To lastrow
ws2name = ws.Cells(rownum, 5)
Set ws2 = Sheets(ws2name)
lastrow2 = ws2.Cells(ws2.Rows.Count, "E").End(xlUp).Row
ws.Rows(rownum).copy ws2.Rows(lastrow2 + 1)
Next rownum
End Sub
I have data in RAW DATA sheet and I am copying data from this sheet to other by using this macro. I have data till column H in RAW DATA sheet, now in a new column added for example if in column H Text is there as "ABC" in any row then I want that row shouldn't be copied to other sheets & it should be copied to sheet name "ABC" instead of the sheet name mentioned in column E, for this what should be the change in the code ??