+ Reply to Thread
Results 1 to 9 of 9

If value in cell look in next column and replace it VBA

  1. #1
    Registered User
    Join Date
    04-14-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    28

    If value in cell look in next column and replace it VBA

    hi all,

    working on this:

    HTML Code: 
    Basically, I have value in columns A and B:
    Capture.PNG



    I would like to write a function so in the column D the text would be replaced from value in A to value in B.

    so in this example, i Would have "t hello y", as "aa" and "bbb" are in the column A and the respectively value in column B are "t" and "y".

    should have another function something like:



    HTML Code: 

    Many thanks

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: If value in cell look in next column and replace it VBA

    I would like to write a function so in the column D the text would be replaced from value in A to value in B.
    This code accomplishes that. I'm a little confused by what you are attempting with the function at the end of your post.

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: If value in cell look in next column and replace it VBA

    Is it really a function you want or just a subroutine ??
    - Battle without fear gives no glory - Just try

  4. #4
    Registered User
    Join Date
    04-14-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    28

    Re: If value in cell look in next column and replace it VBA

    Hi and thanks for the subroutine! It works well!

    I was thinking about the function as if I have a variable "Text" for all the values in column D and in any other cells, would be easier to have it as function. So instead of declaring columns(4) in "Columns(4).Replace c.Value, c.Offset(0, 1).Value", I would like to have just a variable "Text", so for each "Text" make does changes.

    Thanks a lot again!

  5. #5
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: If value in cell look in next column and replace it VBA

    Sorry, I'm still confused. Need to see an example that shows

    1) sample data
    2) sample formula
    3) expected formula output

  6. #6
    Registered User
    Join Date
    04-14-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    28

    Re: If value in cell look in next column and replace it VBA

    the subroutine work perfectly and is everything i need. just want to use a function instead, so if I have Text as )String, would be something like:

    HTML Code: 

    so if Text contains one of the value in Column A, then replace it with value in column B (exactly the same that you did in the subroutine).

    Hope I explained it better and thanks a lot!

  7. #7
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: If value in cell look in next column and replace it VBA

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-14-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    28

    Re: If value in cell look in next column and replace it VBA

    Great, this is perfect! thanks a lot!

  9. #9
    Registered User
    Join Date
    04-14-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    28

    Re: If value in cell look in next column and replace it VBA

    Is there any way to adjust this function so is going to replace only the exact matches. For example:


    Capture.PNG


    so is not going to replace values between text, but only when the exact conditions are met. So in this case is fine if the text in column C is going to be replace as it shown in column E, as "aaa" is going to become "a", "bbb" is going to become "b", but "abaaa" is not going to change, as "abaaa" is not in column A.

    Thanks a lot!

    Thanks
    Last edited by ghostexcel; 04-26-2016 at 04:54 AM. Reason: only exact match in a string

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to replace the character in one cell with the value in another column
    By bayala87 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 09-18-2015, 02:15 PM
  2. [SOLVED] Excel VBA to replace letters in each cell in a column
    By emina_c in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2015, 10:31 AM
  3. [SOLVED] Replace cell in Column A with value in Column B if contains similar character string
    By oybombadil in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-17-2015, 08:49 AM
  4. How to use VBA to replace cell content in a column
    By Ray Tejeda in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-22-2012, 01:58 PM
  5. [SOLVED] How do I replace cell contents or add another column.
    By KELLIS in forum Excel General
    Replies: 6
    Last Post: 05-10-2012, 12:02 PM
  6. Replies: 4
    Last Post: 03-12-2012, 10:46 AM
  7. Search Column for value in Cell & Replace
    By janglin in forum Excel General
    Replies: 5
    Last Post: 08-22-2006, 11:00 PM

Tags for this Thread

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