View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bryan Kelly Bryan Kelly is offline
external usenet poster
 
Posts: 25
Default Help with find and replace routine

ste suggested I use:

set rng = sheets("sheet1").Range("A1:A10").Find("actualAxis1 ")


If I use sheets("sheet1") then the sheet where I am searching must be named
"sheet1"
This macro is to be a general purpose macro and the sheet that is being
searched may
be named "sheet6" or "data" or anything else. I don't know much about excel
macros
but I do now there is a way to say search the active sheet regardless of its
name.

If I use Range("A1:A10"), that may work, but what if my next search is in a
sheet that
has the data in cell A43. When manually performing a search using ctl-f,
the user can
select a row, select a column, select an area, or not select anything. In
all of those cases,
the "find" operates and tells me where the data was found.

Shifting perspective a bit:

When I am editing a macro, I put the cursor on "Range" (for example) and
press F1, Excell
gives me a screen full of data but does not explain what that data means.
If I already know,
its a good reminder. If I don't already know, it is little use.

When I look in a book on Excel macros I purchased and look up ranges, it has
ranges embedded
in statements and doesn't tell me its methods, arguments, and return values.
No help.

Here is my question again:

I am trying to say to Excel: In the current sheet search the whole sheet
(regardless of its size)
and tell me where you find the string "actualAxis1"

Then I want to say something like:

cell [ cell_index ] = "AZ"

Or, in that cell where you just found string "actualAxis1", enter the string
"AZ" replacing what was there.
And by the way, if you don't find the string, that's okay. Do not jump into
the debugger, do not
tell me you failed, do not try to replace anything, just go on to the next
statement in the macro.

in pseudo code it can be written as follows:

cell_index = find( "actualAxis1" )
if found
set cell [ cell_index ] = "AZ"
end if

And just in case, in the line
cell_index = find( "actualAxis1" )
The symbols "(" and ")" mean that the data between them is an argument to a
function or method.
And in the line
set cell [ cell_index ] = "AZ"
The symbols "[" and "]" mean that the data between them specify the index of
an array.
An Excel spreadsheet can be considered an array of cells.

Thank you for your time,
Bryan


"ste mac" wrote in message
om...
Hi Bryan,

I think you need to enter the sheet name to search and the range on the

sheet
so the code knows where to look..

I am having problems with this.
anonymous wrote:
Set rng = Sheets("xxx").Range("xxx").Find(whatyou want)

I don't know what to put in for the xxx strings so I have progressed to

this
point:
Set rng = ActiveSheets.Range("xxx").Find("actualAxis1")


i.e
set rng = sheets("sheet1").Range("A1:A10").Find("actualAxis1 ")

This means it looks in sheet1 (or what ever you sheet is named on the tab)
and then searches in the range A1 through A10 (obviously you will have to
put the correct range in, that is which cells you want it to search)...

I hope this helps...

seeya ste