+ Reply to Thread
Results 1 to 6 of 6

If Column A contains one of several strings then change column Bs string

  1. #1
    Registered User
    Join Date
    01-04-2010
    Location
    Virginia
    MS-Off Ver
    Excel 2003
    Posts
    11

    If Column A contains one of several strings then change column Bs string

    I am fairly new to macros in excel however I have done programming before. My biggest problem is figuring out the syntax for everything. So wondering if you guys could give me a hand.

    What I need is to check to see if a cell in a column matches one of several different strings. If it does then I need to change another cell in the same row but different column to say DELETE. If it does not contain that string then I simple delete it So far I have this

    Please Login or Register  to view this content.
    Alternatively I could delete all of the un needed rows then go back with another macro to change all of row B to say DELETED. I still face the problem of not knowing how to format a cell change.
    Last edited by Vestax159; 01-04-2010 at 11:49 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: If Column A contains one of several strings then change column Bs string

    1) Go ahead and break the habit of using .UsedRange in your method for determining the first and/or last row of data. It is full of holes and when it does break you won't know it, you just won't know it's doing wrong things to your data.

    Instead, pick the row that always has data filled in, like column A, and just evaluate that column directly.
    Please Login or Register  to view this content.
    2) Before you run your loop, delete all the "error" rows first to speed up the process, they're no longer there to have to be evaluate. This one line of code will delete every row that has a formula in that results in an error in column A:
    Please Login or Register  to view this content.
    3) Maybe this then:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-04-2010 at 11:57 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-04-2010
    Location
    Virginia
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: If Column A contains one of several strings then change column Bs string

    I created a test and made two columns A and B then a filled each row going down with ItemA ItemB etc for 4 rows.

    Original
    A B
    1 ItemA ItemA
    2 ItemB ItemB
    3 ItemC ItemC
    4 ItemD ItemD

    Result
    A B
    1 ItemA ItemA
    2 ItemB Here
    3 ItemC Here
    4

    Cells A4 and B4 were both blank i'm suspecting the cost begins 1 cell to late and ends 1 cell to early?

    Please Login or Register  to view this content.
    Last edited by Vestax159; 01-05-2010 at 12:22 AM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: If Column A contains one of several strings then change column Bs string

    Most people have some sort of "titles" in row 1, if you don't it's a simple adjustment:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-04-2010
    Location
    Virginia
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: If Column A contains one of several strings then change column Bs string

    Thanks alot for your help so far! I have have another question with this though. I am trying to check the cells in column A against a huge amount of information (thousands). At first I tried pasting them where items A,B,C are however the amount of information is so large that they wrap around to the next line. I checked to see if I could find word wrap option but I don't think this is the case since it continues on the next line in the middle of a word. IT appears as if I simple ran out of space on that line. Is there some way to disable it or to continue on the next line?

    I commented the area which I am talking about. If I am being unclear let me know.


    Please Login or Register  to view this content.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: If Column A contains one of several strings then change column Bs string

    You use a space-underscore combination to break long strings.
    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