Excel crashing while running a code

rinijg

New Member
Joined
May 13, 2011
Messages
47
I have a code to find out for a particular text in all the worksheets of a workbook and if a text is there in a particular worksheet, the name of that worksheet will be be copies to a cell in Sheet1. Following is the code

Code:
Sub searchname_Click()
     
    Dim ThisAddress$, Found, FirstAddress
    Dim Lost$, N&, NextSheet&
    Dim CurrentArea As Range, SelectedRegion As Range
    Dim Reply As VbMsgBoxResult
    Dim FirstSheet As Worksheet
    Dim Ws As Worksheet
    Dim Wks As Worksheet
    Dim Sht As Worksheet
 
    Set FirstSheet = ActiveSheet '< bookmark start sheet
    Lost = InputBox(prompt:="Type in the   details you are looking for!", _
    Title:=" Find what?", Default:="*")
    If Lost = Empty Then End
    For Each Ws In Worksheets
        Ws.Select
        With ActiveSheet.Cells
            Set FirstAddress = .Find(What:=Lost, LookIn:=xlValues)
            If FirstAddress Is Nothing Then '< blank sheet
                Next Ws
            End If
            FirstAddress.Select
            
            With Selection
                Set Found = .Find(What:=Lost, LookIn:=xlValues)
                If Not Found Is Nothing Then
                    FirstAddress = Found.Address
                  
                End If
            End With
            Selection.Copy
              
          Worksheets("Sheet1").Range("a65536").End(xlUp).Offset(1, 0).Value = ActiveSheet.Name
           
           Next Ws
 FirstSheet.Select
   
End Sub

But the excel is crashing when i run this code. Could you please help me out??
 
Now its working absolutely fine... It was my mistake in copying the code...

Thanks a ton.... I am so relieved now :):)
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Just to clarify, Next isn't just a command, it's actually part of the structure of the program. You can't just issue a Next command and expect the program to go to the next cycle of the For loop - each Next must have one and only one matching For command, in the same way as every Do must have exactly one matching Loop, every If must have exactly one matching End If, every Select must have exactly one matching End Select, and vice versa.

So you can't do this:-
Code:
For x = 1 To 100
  [COLOR=green]' some code[/COLOR]
  If xyz = 0 Then
    Next x
  End If
  [COLOR=green]' some more code[/COLOR]
Next x
You would have to do this:-
Code:
For x = 1 To 100
  [COLOR=green]' some code[/COLOR]
  If xyz <> 0 Then
    [COLOR=green]' some more code[/COLOR]
  End If
Next x
Hope this helps (for future reference).
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

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