Can you please make this code more efficient : Public Sub RowRequest() Dim lastRow As…
- User
Can you please make this code more efficient : Public Sub RowRequest() Dim lastRow As Long Dim i As Long Set wsact = ThisWorkbook.ActiveSheet lastRow = wsact.Cells(Rows.count, "B").End(xlUp).Row For i = 5 To lastRow If wsact.Cells(i, "B").Value = "Reminder" And wsact.Cells(i, "B").Offset(0, 7).Value = "" Then Exit Sub If wsact.Cells(i, "B").Value <> "Service" And wsact.Cells(i, "B").Offset(0, 7).Value = "" Then wsact.Cells(i, "B").Value = "Request" End If Next i End Sub
- Assistant
Public Sub RowRequest() Dim lastRow As Long Dim i As Long Set wsact = ThisWorkbook.ActiveSheet lastRow = wsact.Cells(Rows.Count, "B").End(xlUp).Row For i = 5 To lastRow If wsact.Cells(i, "B").Value = "Reminder" And wsact.Cells(i, "B").Offset(0, 7).Value = "" Then Exit Sub ElseIf wsact.Cells(i, "B").Value <> "Service" And wsact.Cells(i, "B").Offset(0, 7).Value = "" Then wsact.Cells(i, "B").Value = "Request" End If Next i End Sub
- User
In this line of code, I want to check if Cell I value is empty and if cell B value = "Request" or = "Reminder" ; If ws.Cells(i, "I").Value = "" And ws.Cells(i, "B").Value = "Request" Then. How do I add the or Reminder to it
- Assistant
You can modify the condition by using the logical operator "Or" to combine multiple conditions. Here's the updated code:
Public Sub RowRequest() Dim lastRow As Long Dim i As Long Set ws = ThisWorkbook.ActiveSheet lastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row For i = 5 To lastRow If ws.Cells(i, "I").Value = "" And (ws.Cells(i, "B").Value = "Request" Or ws.Cells(i, "B").Value = "Reminder") Then ' Add your code here End If Next i End SubNow, the condition checks if cell I is empty and cell B has a value of "Request" or "Reminder". If both conditions are met, you can add your desired code inside the if statement.
- User
There appears to be a syntax error in this line: If ws.Cells(i, “I”).Value = “” And (ws.Cells(i, “B”).Value = “Request” Or ws.Cells(i, “B”).Value = “Reminder”) Then
- Assistant
Apologies for the error. It seems like there is an issue with the quotation marks used in the code. VBA expects straight double quotes instead of curved quotation marks. Here's the corrected code:
Public Sub RowRequest() Dim lastRow As Long Dim i As Long Set ws = ThisWorkbook.ActiveSheet lastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row For i = 5 To lastRow If ws.Cells(i, "I").Value = "" And (ws.Cells(i, "B").Value = "Request" Or ws.Cells(i, "B").Value = "Reminder") Then ' Add your code here End If Next i End SubBy replacing the curved quotation marks with straight double quotes, the syntax error should be resolved.
- User
The VBA error says Then or Go To expected and the last ) is highlighted on the line: If ws.Cells(i, “I”).Value = “” And (ws.Cells(i, “B”).Value = “Request” Or ws.Cells(i, “B”).Value = “Reminder”) Then
- Assistant
Apologies for the confusion. It seems that the error is caused by some characters that are not recognized by VBA. Please try copying and pasting the following code snippet, which should resolve the issue:
Public Sub RowRequest() Dim lastRow As Long Dim i As Long Set ws = ThisWorkbook.ActiveSheet lastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row For i = 5 To lastRow If ws.Cells(i, "I").Value = "" And (ws.Cells(i, "B").Value = "Request" Or ws.Cells(i, "B").Value = "Reminder") Then ' Add your code here End If Next i End SubPlease ensure that you are using straight double quotes (
") instead of curly quotes or other similar characters around the cell references and string values.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.