works on XP but not on vista

S

Sheela

Hi I have following code to search and for specific words and then delete the
rows between ( including them) those rows.
This macro works fine on a XP machine, but not working properly on Vista.

While debugging the code by “step intoâ€, I realized the “WS. Find†function
not finding the rows, even though those words are exist in the first column.
I am trying modify the code to other than “WS.columns.find†function, but
can you help me to find out why it is not working on Vista, the way it is
supposed to be?
thank you so much for your help
########
Public Sub Paste_Transpose_Specific()
Dim WS As Worksheet
Dim Trialrow, Summaryrow As Range
On Error Resume Next

For Each WS In ActiveWorkbook.Worksheets
With WS
Set Trialrow = WS.Columns(1).Find("Sample", Range("A1"),
SearchOrder:=xlByRows, SearchDirection:=xlNext)

Set Summaryrow = WS.Columns(1).Find("Total:", Range("A1"),
SearchOrder:=xlByRows, SearchDirection:=xlPrevious)

If Not (Trialrow Is Nothing) And Not (Summaryrow Is Nothing) Then _
WS.Rows(Trialrow.Row & ":" & Summaryrow.Row).Delete


End With


Next WS
On Error GoTo 0
 
J

joel

The problem probably isn't the difference between 2003 and 2007. Th
find function uses the same function as the worksheet find (2003 men
Edit - find). the find doesn't have a default value for some of th
parameters. the find uses whatever was last set in the worksheet. S
you probably just have to add all the parameters in the find function.
OPen up the worksheet find and look at the option. You will see that i
is set incrorrectly.

expression.Find(What, After, LookIn, LookAt, SearchOrder
SearchDirection, MatchCase, MatchByte, SearchFormat)


Usually as a mimimum you need to specfiy the

LookIn:=xlvalues, lookat:=xlwhole, MatchCase:=False

Lookat can also be xlpart


The most common failure like this is the Part vs Whol
 
P

Patrick Molloy

additionally change this
Dim Trialrow, Summaryrow As Range

to
Dim Trialrow As Range, Summaryrow As Range


in your code, Trialrow is variant by default since you need to explicitly
set its type. However, it doesn't affect your code, I'm just being picky :)
 
S

Sheela

I did not know that defining variables in one row vs. separate rows makes a
difference.

I changed the all the definitions in my code each one in a separate line.
thank you.

sheela
 
P

Patrick Molloy

you can certainly dimension variables in a row..

DIM a as long, b as long, c as long

is the same as

DIM a as long
DIM b as long
DIM c as long

but
DIM a, b, c as long

only dims the last variable,c, explcitly as long. Both a and b are variants
since they are not explicitly typed.
 
J

joel

Patrick Molloy: I don't think Sheela was refering to the Dim statements
Sheela was refering to the properties of the VBA Find. That settin
the properties in one Find to (ie xlpart) means that the following Fin
statments would also use xlpart not xlwhole. VBA find is unlike othe
methods that is doesn't use a default setting, instead it use the las
setting which could also include any time the FIND is used in th
worksheet menu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top