+ Reply to Thread
Results 1 to 5 of 5

Creating a macro: If Cell A1 contains x then add x to the end of a string of text.

Hybrid View

  1. #1
    Registered User
    Join Date
    02-27-2012
    Location
    Dorset, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Question Creating a macro: If Cell A1 contains x then add x to the end of a string of text.

    Hi all,

    I'm not confident by title describes my problem very well but what I'm trying to do is the following:

    My spreadsheet is used to track cars and every month I add new cars to it. At the moment I can download the details of said cars which I break into separate cells using text to columns.

    The car model is displayed as a string of text and the transmission is recorded in a different cell as M(anual) or A(utomatic). What I'd like a macro to do, it check each row to see firstly if the car is an Automatic, if it is, then I'd like it to add the text AUTO to the end of the existing model description. If it's Manual then I'd like it to do nothing.

    Also (as if this wasn't tricky enough) in SOME circumstances the model of the car might already have the text AUTO in it. In these cases (if possible) I'd like the macro to skip and not add the text in again.

    Hopefully that explains things enough but if not then please ask me anything else which will help.

    Many many thanks for any and all help I receive.
    Last edited by Coolcatfish; 02-27-2012 at 10:38 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Creating a macro: If Cell A1 contains x then add x to the end of a string of text

    Why dont you attach a sample file with enough samples for us to identify the variations in your data?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Creating a macro: If Cell A1 contains x then add x to the end of a string of text

    Hi,

    You don't really need a macro.

    With the model of car in A1 and A or M in B1, use:
    =IF(B1="A",A1&IF(ISERROR(FIND("Auto",A1))," Auto",""),A1)
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    02-27-2012
    Location
    Dorset, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Creating a macro: If Cell A1 contains x then add x to the end of a string of text

    Thank you both, Richard your suggestion works a charm.

    Thanks again.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Creating a macro: If Cell A1 contains x then add x to the end of a string of text

    Hi,

    Thanks for the feedback.

    Regards

+ 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