Please write an Excel VBA code that will perform the following: For all sheets in a…
- User
Please write an Excel VBA code that will perform the following: For all sheets in a workbook where the sheet name has only three letters, search column 'B' for the text value'Remind'.
For each text value 'Remind' found in cloumn 'B' copy the column values in C, E, J and L that are on the same row with column 'B' and paste the values into sheet 'Reminders' starting at row 23 in the following order.
On the same row as column 'B' where the text value 'Remind' is found, copy the value of column 'J' to Column 'D' in the sheet 'Reminder' of the same workbook On the same row as column 'B' where the text value 'Remind' is found, copy the value of column 'L' to Column 'E' in the sheet 'Reminder' of the same workbook On the same row as column 'B' where the text value 'Remind' is found, copy the value of column 'C' to Column 'F' in the sheet 'Reminder' of the same workbook On the same row as column 'B' where the text value 'Remind' is found, copy the value of column 'E' to Column 'G' in the sheet 'Reminder' of the same workbook.
After each Row paste into sheet 'Reminder' move down one row to paste the next results of the next text value 'Remind' that is found.
- Assistant
Sure! Here's an Excel VBA code that performs the desired actions:
Sub CopyRemindersToSheet() Dim wb As Workbook Dim ws As Worksheet Dim reminderSheet As Worksheet Dim lastRow As Long Dim i As Long Dim j As Long Set wb = ThisWorkbook Set reminderSheet = wb.Sheets("Reminders") ' Clear previous data in the reminder sheet starting from row 23 reminderSheet.Range("D23:G" & reminderSheet.Cells(reminderSheet.Rows.Count, "D").End(xlUp).Row).ClearContents ' Loop through each sheet in the workbook For Each ws In wb.Sheets ' Check if the sheet name has only three letters If Len(ws.Name) = 3 Then lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row ' Loop through each cell in column B For i = 1 To lastRow ' Check if the cell value is "Remind" If ws.Cells(i, "B").Value = "Remind" Then ' Copy values from columns C, E, J, and L reminderSheet.Cells(reminderSheet.Rows.Count, "D").End(xlUp).Offset(1, 0).Value = ws.Cells(i, "J").Value reminderSheet.Cells(reminderSheet.Rows.Count, "E").End(xlUp).Offset(1, 0).Value = ws.Cells(i, "L").Value reminderSheet.Cells(reminderSheet.Rows.Count, "F").End(xlUp).Offset(1, 0).Value = ws.Cells(i, "C").Value reminderSheet.Cells(reminderSheet.Rows.Count, "G").End(xlUp).Offset(1, 0).Value = ws.Cells(i, "E").Value End If Next i End If Next ws End Sub