+ Reply to Thread
Results 1 to 7 of 7

Changing cells based on content

  1. #1
    Registered User
    Join Date
    09-19-2006
    Posts
    6

    Changing cells based on content

    How can I get an excel macro to change a selected column's individual cell content based on that cell's content. For example, if have a column with either e or c in each cell I want the macro to change the c's into 0's and the e's into 1's.

    Is that possible? How would I go about doing that?

  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Please Login or Register  to view this content.

    HTH
    Col
    If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.

  3. #3
    Registered User
    Join Date
    09-19-2006
    Posts
    6
    That worked almost perfectly! Is there anyway to have the macro work on the selected column instead of having to edit the macro every time?

    or

    I just thought of somethings else...does "with [a:a]" mean column A through column A? Would "with [a:c]" mean column A through column C? I could just copy and paste it over and over again with the exact columns I need correct?

    -- BAC240SX

  4. #4
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Yup, that's exactly right, [a:c] is shorthand for Range("A:C"), columns A thru C, so "With [a:c]" would apply the Replaces to the three of them.

    Or, to answer your first question, "With Selection.EntireColumn" would apply them to the whole columns in which cells are selected - however many cells are selected, even if they are not contiguous, so you could select A1, D4 and Q73, if you wanted, and it would work on the whole of columns A, D and Q.


    C

  5. #5
    Registered User
    Join Date
    09-19-2006
    Posts
    6
    Thanks buddy! That was what I wanted, only, now the idea of selecting all those columns seems tedious (I know I'm lazy, but isn't that the point of a macro, and we are talking about a hundred or so columns)

    Is there a way to have the macro select a range of columns, say for example "with [a:z]" but exclude columns b, g, and y?

  6. #6
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Comma-delimit the distinct ranges, e.g. [a:a,c:f,h:x,z:z]


    C

  7. #7
    Registered User
    Join Date
    09-19-2006
    Posts
    6
    Perfection, you saved my countless hours in the lab, thankyou!!!

+ 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