Shorten/simplify/improve/make more efficient this bit of code

Truiz

Active Member
Joined
Jul 14, 2014
Messages
339
Good day lads,

I have this code

Code:
For iCntr = lRow To 1 Step -1                                           If Cells(iCntr, "L") = "Close" Then                                 
    Rows(iCntr).Delete                                                  
    End If                                                              
    Next                                                                
                                                                        
    For iCntr = lRow To 1 Step -1                                       
    If Cells(iCntr, "L") = "Close Supervised + Auto Notify" Then        
    Rows(iCntr).Delete                                                  
    End If                                                              
    Next                                                                
                                                                        
    For iCntr = lRow To 1 Step -1                                       
    If Cells(iCntr, "L") = "Fail to Close" Then                         
    Rows(iCntr).Delete                                                  
    End If                                                              
    Next                                                                
                                                                        
    For iCntr = lRow To 1 Step -1                                       
    If Cells(iCntr, "L") = "Fail To Open" Then                          
    Rows(iCntr).Delete                                                  
    End If                                                              
    Next


I wrote it as such cuz i'm no expert in VBA I was wondering if there is a way to shorten the code I mean it works and everything I just think in looks dirty to have that.

Regards,
 
I encountered an issue.

One of the strings I want to delete is AR/Billing "Insurance" as you can see it has quotation marks, thus creating a syntax error
You have to double up quote marks that are located inside the quote marks that delineate the text string. For my code...
Code:
[table="width: 500"]
[tr]
	[td]For iCntr = lRow To 1 Step -1
  Select Case Cells(iCntr, "L")
    Case "Close", "Close Supervised + Auto Notify", "Fail to Close", "Fail To Open", "AR/Billing [B][COLOR="#FF0000"][SIZE=3]""[/SIZE][/COLOR][/B]Insurance[B][COLOR="#FF0000"][SIZE=3]""[/SIZE][/COLOR][/B]"
      Rows(iCntr).Delete
  End Select
Next[/td]
[/tr]
[/table]
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You have to double up quote marks that are located inside the quote marks that delineate the text string. For my code...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]For iCntr = lRow To 1 Step -1
  Select Case Cells(iCntr, "L")
    Case "Close", "Close Supervised + Auto Notify", "Fail to Close", "Fail To Open", "AR/Billing [B][COLOR=#FF0000][SIZE=3]""[/SIZE][/COLOR][/B]Insurance[B][COLOR=#FF0000][SIZE=3]""[/SIZE][/COLOR][/B]"
      Rows(iCntr).Delete
  End Select
Next[/TD]
[/TR]
</tbody>[/TABLE]


Whe I first worte it It didn't work, can't really tell how or why but eventually it did thanks.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top