DoUntil loop delete

julhs

Active Member
Joined
Dec 3, 2018
Messages
471
Office Version
  1. 2010
Platform
  1. Windows
I know I need a loop for this but I just can’t construct it (Using "GoTo line simply for testing")

VBA Code:
If Selection.Cells.Count > 2 Then
  MsgBox "Want to continue and clean things up ? "
    FirstRow = Range("MyRange").Cells.Find("*", SearchOrder:=xlByRows, _
      SearchDirection:=xlNext).Row
    LastRow = Range("MyRange").End(xlDown).Row
Line1:
    Range("B" & FirstRow - 1).Select
    Range("B" & FirstRow - 1).Delete
    Range("MyRange").Select
 If Selection.Cells.Count > 2 Then
   GoTo line1
Else
   Range("MyRange").ClearContents
End If
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Thank you for info.
What you gave me and everything I’ve searched SHOULD give me what I need to do this.
But I'm struggling to decipher it and apply it to my scenario.
 
Upvote 0
Try this
VBA Code:
If Selection.Cells.Count > 2 Then
  MsgBox "Want to continue and clean things up ? "
    FirstRow = Range("MyRange").Cells.Find("*", SearchOrder:=xlByRows, _
      SearchDirection:=xlNext).Row
    LastRow = Range("MyRange").End(xlDown).Row
Do Until Selection.Cells.Count > 2
    Range("B" & FirstRow - 1).Select
    Range("B" & FirstRow - 1).Delete
    Range("MyRange").Select
 Loop
Else
   Range("MyRange").ClearContents
End If
 
Upvote 0
Solution
Thanks for that.
Feel like a right clown for not being able to decipher things, obviously had a complete mental time out.
Did have to make couple of changes though.
VBA Code:
Do Until Selection.Cells.Count > 2
Needed to be
VBA Code:
Do Until Selection.Cells.Count = 2
And no longer needed
VBA Code:
Else
All good now.
Many thanks for your help
Julhs
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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