+ Reply to Thread
Results 1 to 5 of 5

Find and replace on all sheets

  1. #1
    Registered User
    Join Date
    01-13-2010
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Question Find and replace on all sheets

    Hi! I am using Excel 2007. I know enough to be dangerous but rarely write code from scratch.

    This is what I am looking for:

    Look in Sheet 1, cell A1. If A1 contains "Clinical", go to G14 and clear contents of G14.
    After clearing G14 or if A1 doesn't contain "Clinical", move to Sheet 2, cell A1.
    Look at Sheet 2 A1. If Sheet 2 A1 contains "Clinical", go to Sheet 2 G14 and clear contents....etc.

    This file has 30 or so sheets to run through. I have multiple functions I will have to do (besides clearing G14). I may need to look for other text and delete certain rows. I can probably write that if I get the basic IF and loop set up.

    I haven't had good luck with IF statements and haven't tried writing a loop.

    Thanks for any and all help!!

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Help with If, find and replace looping through each sheet of workbook

    Like so?
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-13-2010
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Help with If, find and replace looping through each sheet of workbook

    StephenR,
    Thanks for the code! It worked perfectly.

    Now I am trying to modify it for other functions and I am hung up on something that's probably obvious to you.

    I want to go through the sheets and select cell F8 and put the formula ='Global Input'!$C$5 in it on each sheet. It doesn't like the line
    Please Login or Register  to view this content.
    . I get Run-time error '1004': Select method of Range class failed.Can you tell me why?

    Here is the entire code:
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Help with If, find and replace looping through each sheet of workbook

    Well we can dispense with the Select, not generally recommended anyway, so see if this works:
    Please Login or Register  to view this content.
    Your code probably errored because the cell was being selected on a non-active sheet as the code does not require the sheets to be selected as it loops through.

  5. #5
    Registered User
    Join Date
    01-13-2010
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find and replace on all sheets

    StephenR,

    Thanks for the help again. I particularly appreciate the explanation of why it didn't work. My goal is to move beyond recording macros and modifying them. I am working my way through Walkenbach's "Excel2007 VBA Programming for Dummies".

    Thanks for your patience!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1