+ Reply to Thread
Results 1 to 8 of 8

Editing a Range

  1. #1
    Registered User
    Join Date
    07-07-2009
    Location
    San Francisco
    MS-Off Ver
    Excel 2003
    Posts
    16

    Editing a Range

    Hi,

    So I am attempting to run a macro that contains some if then statements that will change the text in a cell given certain circumstances. I am having an issue specifying the range in that it begins in cell A2 and it goes to the last data cell in the sheet and no farther. The issue with just selecting a whole column is that if the a cell is blank, it fills it in with no and it leaves me with 65,xxx nos in column A. Attached is the workbook with the sheet the code would be executed on and hopefully what the solution would look like. Also i have attached the troublesome macro I have written.

    Please Login or Register  to view this content.
    Thanks in advance.
    Attached Files Attached Files
    Last edited by cdmcnamara; 07-15-2009 at 08:29 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Editing a Range

    There are a couple of issues with your code.

    Firstly your set range staement is referring to the row number of the last cell in the range, not the actual range. Note I have changed it so that it now refers to a range that starts at A2 and ends in the last cell in the range (edit: you have to delete all the data in columns B:D in your sample sheet.

    Secondly your For Each loop should not include .cells at the end

    Please Login or Register  to view this content.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Editing a Range

    Here's another way:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    07-07-2009
    Location
    San Francisco
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Editing a Range

    MallyCat,
    Thanks for your help but when I run that on a sheet with more than one column it changes all the values in the sheet, I was hoping to have it only edit one column, which I specify.

    Thanks1

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Editing a Range

    Or, without a loop,
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-07-2009
    Location
    San Francisco
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Editing a Range

    Thanks to both of you guys, shg's code seemed to work for a specified column.

  7. #7
    Registered User
    Join Date
    07-07-2009
    Location
    San Francisco
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Editing a Range

    Shg,

    The .SpecialCells(xlCellTypeConstants, xlTextValues) macro runs great the first time you run it, but if you run it again it takes out all the Nos and and replaces them with Yes, is there anyone you can make it so if it says no in it dont replace it with yes?

    Thanks!

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Editing a Range

    You'd have to go back to the loop:
    Please Login or Register  to view this content.

+ 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