method not found in this code: ws.Range("C" & cell.row).Copy…
- User
method not found in this code: ws.Range("C" & cell.row).Copy ws.Sheets("Reminders").Range("F" & row)
- Assistant
The method not found in this code is the ".Copy" method.
- User
How can I fix it
- Assistant
To fix the issue, you can use the ".Copy" method with the correct syntax. Here's the modified code:
ws.Range("C" & cell.row).Copy Destination:=ws.Sheets("Reminders").Range("F" & row)By adding "Destination:=", you can specify the destination range where you want to copy the data to.
- User
ws.Range("C" & cell.row).Copy Destination:=ws.Sheets("Reminders").Range("F" & row) . . . I am getting a Method error on the word Sheets
- Assistant
Apologies for the confusion. The error you're encountering is likely due to using "Sheets" instead of "Worksheets" in the code. "Sheets" is a generic term that can refer to both worksheets and chart sheets, whereas "Worksheets" specifically refers to worksheets.
Here's the modified code:
ws.Range("C" & cell.row).Copy Destination:=ws.Worksheets("Reminders").Range("F" & row)Please make sure to replace "Sheets" with "Worksheets" to resolve the issue.
- User
I am getting an error Method or Data member not found on.Worksheets in the event below:
Sub AllReminders() 'Bards code
'Declare variables Dim ws As Worksheet Dim cell As Range Dim i As Long Dim row As Long
'Set starting row in Reminders sheet row = 23
'Loop through all sheets in workbook For Each ws In ThisWorkbook.Sheets
'If sheet name has only three letters, then search for "Remind" in column B If Len(ws.Name) = 3 Then
'Find all cells with value "Remind" in column B For Each cell In ws.Range("B:B").FindAll("Remind")
'Copy the values from columns C, E, J, and L to the Reminders sheet ws.Range("C" & cell.row).Copy Destination:=ws.Worksheets("Reminders").Range("F" & row) ws.Range("E" & cell.row).Copy Destination:=ws.Worksheets("Reminders").Range("G" & row) ws.Range("J" & cell.row).Copy Destination:=ws.Worksheets("Reminders").Range("D" & row) ws.Range("L" & cell.row).Copy Destination:=ws.Worksheets("Reminders").Range("E" & row)
'Move down one row in Reminders sheet row = row + 1
End If
Next cell
Next ws
End Sub
- Assistant
Apologies for the confusion again. The issue lies in referencing the "Worksheets" collection within the loop, which is causing the "Method or Data member not found" error.
Here's the corrected code:
Sub AllReminders() 'Declare variables Dim ws As Worksheet Dim cell As Range Dim i As Long Dim row As Long 'Set starting row in Reminders sheet row = 23 'Loop through all sheets in workbook For Each ws In ThisWorkbook.Worksheets 'If sheet name has only three letters, then search for "Remind" in column B If Len(ws.Name) = 3 Then 'Find all cells with value "Remind" in column B For Each cell In ws.Range("B:B").FindAll("Remind") 'Copy the values from columns C, E, J, and L to the Reminders sheet ws.Range("C" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("F" & row) ws.Range("E" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("G" & row) ws.Range("J" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("D" & row) ws.Range("L" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("E" & row) 'Move down one row in Reminders sheet row = row + 1 Next cell End If Next ws End Sub - User
I am getting an error End If without Block if in this event: Sub AllReminders() 'Bards code
'Declare variables Dim ws As Worksheet Dim cell As Range Dim i As Long Dim row As Long
'Set starting row in Reminders sheet row = 23
'Loop through all sheets in workbook For Each ws In ThisWorkbook.Sheets
'If sheet name has only three letters, then search for "Remind" in column B If Len(ws.Name) = 3 Then
'Find all cells with value "Remind" in column B For Each cell In ws.Range("B:B").FindAll("Remind")
'Copy the values from columns C, E, J, and L to the Reminders sheet ws.Range("C" & cell.row).Copy Destination:=Worksheets("Reminders").Range("F" & row) ws.Range("E" & cell.row).Copy Destination:=Worksheets("Reminders").Range("G" & row) ws.Range("J" & cell.row).Copy Destination:=Worksheets("Reminders").Range("D" & row) ws.Range("L" & cell.row).Copy Destination:=Worksheets("Reminders").Range("E" & row)
'Move down one row in Reminders sheet row = row + 1
End If
Next cell
Next ws
End Sub
- Assistant
Apologies for the oversight. The "End If" statement should be placed after the innermost "For Each" loop, not after the loop through sheets.
Here's the corrected code:
Sub AllReminders() 'Declare variables Dim ws As Worksheet Dim cell As Range Dim i As Long Dim row As Long 'Set starting row in Reminders sheet row = 23 'Loop through all sheets in workbook For Each ws In ThisWorkbook.Sheets 'If sheet name has only three letters, then search for "Remind" in column B If Len(ws.Name) = 3 Then 'Find all cells with value "Remind" in column B For Each cell In ws.Range("B:B").FindAll("Remind") 'Copy the values from columns C, E, J, and L to the Reminders sheet ws.Range("C" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("F" & row) ws.Range("E" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("G" & row) ws.Range("J" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("D" & row) ws.Range("L" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("E" & row) 'Move down one row in Reminders sheet row = row + 1 Next cell End If Next ws 'End of loop through sheets End Sub - User
Error Method does not support this object or property, I suspect on row = row + 1
- Assistant
Apologies for the confusion. The error is occurring because "row" is a reserved keyword in VBA. To fix it, you can use a different variable name.
Here's the modified code:
Sub AllReminders() 'Declare variables Dim ws As Worksheet Dim cell As Range Dim i As Long Dim newRow As Long 'Set starting row in Reminders sheet newRow = 23 'Loop through all sheets in workbook For Each ws In ThisWorkbook.Sheets 'If sheet name has only three letters, then search for "Remind" in column B If Len(ws.Name) = 3 Then 'Find all cells with value "Remind" in column B For Each cell In ws.Range("B:B").FindAll("Remind") 'Copy the values from columns C, E, J, and L to the Reminders sheet ws.Range("C" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("F" & newRow) ws.Range("E" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("G" & newRow) ws.Range("J" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("D" & newRow) ws.Range("L" & cell.Row).Copy Destination:=Worksheets("Reminders").Range("E" & newRow) 'Move down one row in Reminders sheet newRow = newRow + 1 Next cell End If Next ws 'End of loop through sheets End Sub - User
I am still getting the Object doesnt support this method or property
- Assistant
- User
Public Sub AllReminders() Dim ws As Worksheet Dim reminderSheet As Worksheet Dim lastRow As Long Dim i As Long Dim reminderRow As Long
Set reminderSheet = ThisWorkbook.Sheets("Reminders") reminderRow = 23 For Each ws In ThisWorkbook.Worksheets If Len(ws.Name) = 3 Then lastRow = ws.Cells(ws.Rows.count, "B").End(xlUp).Row For i = 1 To lastRow If ws.Cells(i, "B").Value = "Remind" Then reminderSheet.Cells(reminderRow, "D").Value = ws.Cells(i, "J").Value reminderSheet.Cells(reminderRow, "E").Value = ws.Cells(i, "L").Value reminderSheet.Cells(reminderRow, "F").Value = ws.Cells(i, "C").Value reminderSheet.Cells(reminderRow, "G").Value = ws.Cells(i, "E").Value reminderRow = reminderRow + 1 End If Next i End If Next wsEnd Sub
in the code above how can I change the line of code below to show the Name of the sheet where the value Remind is found;
reminderSheet.Cells(reminderRow, "G").Value = ws.Cells(i, "E").Value
- Assistant
To modify the line to show the name of the sheet where the value "Remind" is found, you can use the
ws.Nameproperty. You can assign it to a variable and then use that variable to set the value of the cell.Here's the modified code:
Public Sub AllReminders() Dim ws As Worksheet Dim reminderSheet As Worksheet Dim lastRow As Long Dim i As Long Dim reminderRow As Long Set reminderSheet = ThisWorkbook.Sheets("Reminders") reminderRow = 23 For Each ws In ThisWorkbook.Worksheets If Len(ws.Name) = 3 Then lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row For i = 1 To lastRow If ws.Cells(i, "B").Value = "Remind" Then reminderSheet.Cells(reminderRow, "D").Value = ws.Cells(i, "J").Value reminderSheet.Cells(reminderRow, "E").Value = ws.Cells(i, "L").Value reminderSheet.Cells(reminderRow, "F").Value = ws.Cells(i, "C").Value reminderSheet.Cells(reminderRow, "G").Value = ws.Name ' Update this line reminderRow = reminderRow + 1 End If Next i End If Next ws End Sub