Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PVT PVT is offline
external usenet poster
 
Posts: 19
Default Macro loop with messagebox

Hi- can you please help me fix the following macro. It "hangs" when
"no" is chosen at the messagebox. How do I make it go to the next cell
in the "if" statement?

Sub DeleteSearchTerm26()
Dim c As Range

With ActiveSheet.Range("A:A")
Do

Set c = .Find("by", LookIn:=xlValues, lookat:=xlPart, _
MatchCase:=False)

If c Is Nothing Then Exit Do
c.Select

If MsgBox("Delete entire row?", vbYesNo) = vbYes Then
c.EntireRow.Delete Else ActiveCell.Offset
(0,1).Select

Loop
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Macro loop with messagebox

On Mar 6, 11:57*am, PVT wrote:
Hi- can you please help me fix the following macro. It "hangs" when
"no" is chosen at the messagebox. How do I make it go to the next cell
in the "if" statement?

Sub DeleteSearchTerm26()
Dim c As Range

With ActiveSheet.Range("A:A")
* * Do

* * * * Set c = .Find("by", LookIn:=xlValues, lookat:=xlPart, _
* * * * * * *MatchCase:=False)

* * * * If c Is Nothing Then Exit Do
* * * * c.Select

* * * * If MsgBox("Delete entire row?", vbYesNo) = vbYes Then
c.EntireRow.Delete Else ActiveCell.Offset
(0,1).Select

* * * * * * *Loop
End With

End Sub


Should that be Inputbox instead of Msgbox? (I've forgotten the little
Excel I knew so that may not be the case.)

Kind regards,
John
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro loop with messagebox

In a previous posting I tried to point out that your Do Loop
was not set up properly because it has no defined stopping
point. It will run forever if it does not find the key word.
Below is a macro that I believe will do what you are trying
to do. Give it a try, and post back with any problems.

Sub getBy()
Dim rng As Range, lr As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = ActiveSheet.Range("A2:A" & lr)
For i = lr To 2 Step -1
If LCase(ActiveSheet.Cells(i, 1).Value) Like "*by*" Then
If MsgBox("DO YOU WANT TO DELETE ENTIRE ROW", _
vbYesNo, "Delete Row?") = vbYes Then
ActiveSheet.Cells(i, 1).EntireRow.Delete
End If
End If
Next
End Sub



"PVT" wrote:

Hi- can you please help me fix the following macro. It "hangs" when
"no" is chosen at the messagebox. How do I make it go to the next cell
in the "if" statement?

Sub DeleteSearchTerm26()
Dim c As Range

With ActiveSheet.Range("A:A")
Do

Set c = .Find("by", LookIn:=xlValues, lookat:=xlPart, _
MatchCase:=False)

If c Is Nothing Then Exit Do
c.Select

If MsgBox("Delete entire row?", vbYesNo) = vbYes Then
c.EntireRow.Delete Else ActiveCell.Offset
(0,1).Select

Loop
End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro loop with messagebox

In case you need to see what is in the cell before deleting the row, you can
use this modified version. The message box will show what the found cell has
in it.

Sub getBy()
Dim rng As Range, lr As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = ActiveSheet.Range("A2:A" & lr)
For i = lr To 2 Step -1
If LCase(ActiveSheet.Cells(i, 1).Value) Like "*by*" Then
If MsgBox("DO YOU WANT TO DELETE: " & Cells(i, 1).Value, _
vbYesNo, "Delete Row?") = vbYes Then
ActiveSheet.Cells(i, 1).EntireRow.Delete
End If
End If
Next
End Sub




"PVT" wrote:

Hi- can you please help me fix the following macro. It "hangs" when
"no" is chosen at the messagebox. How do I make it go to the next cell
in the "if" statement?

Sub DeleteSearchTerm26()
Dim c As Range

With ActiveSheet.Range("A:A")
Do

Set c = .Find("by", LookIn:=xlValues, lookat:=xlPart, _
MatchCase:=False)

If c Is Nothing Then Exit Do
c.Select

If MsgBox("Delete entire row?", vbYesNo) = vbYes Then
c.EntireRow.Delete Else ActiveCell.Offset
(0,1).Select

Loop
End With

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
PVT PVT is offline
external usenet poster
 
Posts: 19
Default Macro loop with messagebox

That was the intention- and it worked perfectly. Thank you for your
help!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MessageBox OrlaLynch Excel Programming 4 August 7th 08 06:02 PM
Multiline Messagebox in VBA Joe[_46_] Excel Programming 5 December 10th 07 08:10 PM
messagebox macro Patrick Bateman Excel Programming 1 November 27th 07 01:26 PM
messagebox help SDH Excel Programming 2 April 19th 07 02:34 AM
messagebox help jimE Excel Programming 3 November 3rd 06 07:49 PM


All times are GMT +1. The time now is 10:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"