473,409 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Run-time error91 VBA

Hi,

I wrote a simple script using find method. But as I ran it there occured Run-time error 91. I couldn't figure out the problem. Can anyone give me any suggestions? Many thanks!

The script is about deleting the contents of unwanted items.
Here is the code:
Sub test()
Dim y as Integer

Set curWSht = Workbooks("book.xls").Worksheets("sheet")
With curWSht.Range("f1:f30000")
For y=1 To 6
findString = noisetype(y)
Set c = .Find(findString, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
.Rows(c.Row).EntireRow.ClearContents
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
Next y
Loop

End With
End Sub
Jul 20 '07 #1
1 1421
SammyB
807 Expert 512MB
Hi,

I wrote a simple script using find method. But as I ran it there occured Run-time error 91. I couldn't figure out the problem. Can anyone give me any suggestions? Many thanks!

The script is about deleting the contents of unwanted items.
Here is the code:
Expand|Select|Wrap|Line Numbers
  1. Sub test()
  2. Dim y as Integer
  3.  
  4. Set curWSht = Workbooks("book.xls").Worksheets("sheet")
  5. With curWSht.Range("f1:f30000")
  6. For y=1 To 6
  7. findString = noisetype(y)
  8. Set c = .Find(findString, LookIn:=xlValues, LookAt:=xlWhole)
  9. If Not c Is Nothing Then
  10. firstAddress = c.Address
  11. Do
  12. .Rows(c.Row).EntireRow.ClearContents
  13. Set c = .FindNext(c)
  14. Loop While Not c Is Nothing And c.Address <> firstAddress
  15. End If
  16. Next y
  17. Loop
  18.  
  19. End With
  20. End Sub
  21.  
Does it work if you take up "Loop" (line 17)?
Expand|Select|Wrap|Line Numbers
  1. Sub test()
  2.     Dim y As Integer
  3.  
  4.     Set curWSht = Workbooks("book.xls").Worksheets("sheet")
  5.     With curWSht.Range("f1:f30000")
  6.         For y = 1 To 6
  7.             findString = noisetype(y)
  8.             Set c = .Find(findString, LookIn:=xlValues, LookAt:=xlWhole)
  9.             If Not c Is Nothing Then
  10.                 firstAddress = c.Address
  11.                 Do
  12.                     .Rows(c.Row).EntireRow.ClearContents
  13.                     Set c = .FindNext(c)
  14.                 Loop While Not c Is Nothing And c.Address <> firstAddress
  15.             End If
  16.         Next y
  17.     End With
  18. End Sub
  19.  
Jul 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to it. I can't run asp files from subdirectories of...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
19
by: Bryan | last post by:
How can i run a bit of code straight from the IDE? Right now i make a temporary button and put the code behind that, then i run debug mode and click on the button. Is there a way to highlight...
9
by: Brett Wesoloski | last post by:
I am new to VS2005. I changed my program.cs file to be a different form I am working on. But when I go to run the application it still brings up the form that was originally declared as new. ...
7
by: Lee Crabtree | last post by:
I remember when I was first getting into .NET Forms programming that there was a rather emphatic rule about not constructing a form before calling Application.Run with it. So this: ...
8
by: David Thielen | last post by:
Hi; In our setup program how do I determine if I need to run "aspnet_regiis –i" and if so, is there an API I can calll rather than finding that program on the user's disk and calling it? --...
3
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.