|
-
Oct 4th, 2009, 06:26 PM
#1
Thread Starter
New Member
[Excel] Office 2007 VB Script for slecting rows
Hello,
I am currently using the following code to select rows where a cell contains a specific value. For example:
Code:
Dim d As Range
Dim rngD As Range
For Each d In Intersect(ActiveSheet.UsedRange, Columns("F"))
If d = "Canceled" Then
If rngD Is Nothing Then Set rngD = d.EntireRow
Set rngD = Union(rngD, d.EntireRow)
End If
Next d
rngD.Select
Selection.Delete
The above code looks for the word canceled and deletes any rows where "canceled" is found in column F.
However, when "canceled" is not in any cell in column F, i get a "Runtime error '91': Object variable or With block variable is not set"
Is there a way around this? I'm a complete novice to VB and generally to most types of programing.
Many thanks!
-
Oct 5th, 2009, 02:15 AM
#2
Re: [Excel] Office 2007 VB Script for slecting rows
use your range object and its built in excel function .find
If you grab the current address and then use it, the object moves to the cell that it finds it in.
Doesn't cancelled have two l's? 
Alternatively, with no code you should be able to flag all rows that have cancelled in a particular cell :-> =IF(ISERROR(FIND("cancelled",B2)),"N","Y")
note that this is case sensative...
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|