+ Reply to Thread
Results 1 to 8 of 8

Replace specific values in a range with cell value in the same row

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Here
    MS-Off Ver
    Excel 2013
    Posts
    16

    Replace specific values in a range with cell value in the same row

    Hello all,

    Scenario: I have two columns, A & B both filled with values. In column B, there are many cells with "NULL" as their value. I want to write a macro that looks for all instances of "NULL" in the entire range of column B, and replaces them with the value of the cell in the same row as Column A. Thus:

    A B
    1 NULL
    2 Hello
    3 NULL

    would become

    A B
    1 1
    2 Hello
    3 3

    Is there any easy way to do this without a for loop, perhaps a built-in vba function that can do this? Thanks everyone.
    Last edited by HughManatee; 09-13-2013 at 04:13 PM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Replace specific values in a range with cell value in the same row

    Formula will do

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-18-2012
    Location
    Here
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Replace specific values in a range with cell value in the same row

    Thanks for the response, but I'm not clear as to how to implement that in VBA. Keep in mind, I'm trying to do this over an entire range in a column (for ~20000 cells). I want something quicker than a for loop. Could you elaborate a bit?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Replace specific values in a range with cell value in the same row

    IMO, you can do it with out a loop if the replacement of a cell does not come from another cell, but you are not.
    Mine is just a simple formula like substitute, but it will not work on column A. You have to do the formula in different column, say in column C and then copy values only back in to column A.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Replace specific values in a range with cell value in the same row

    You can also probably sort the data by column B and all NULL values will be at the top, then copy manually column A in to B It may not be ****, but will avoid looping.

  6. #6
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Replace specific values in a range with cell value in the same row

    You can avoid the loop if you use EVALUATE()

    Please Login or Register  to view this content.
    Gary's Student

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Replace specific values in a range with cell value in the same row

    Jak,
    Brilliant idea!

  8. #8
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Replace specific values in a range with cell value in the same row

    Jut anoter approach..

    Select Column B:B

    Find what : NULL
    Replace with : =indirect("A" & row())

    give a try.. "copy n paste as value" if required..
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

+ 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. Macro to find all specific values in column and replace adjacent cell values
    By dblock02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2013, 06:03 AM
  2. [SOLVED] Calculate/sum multiple values in each cell in a range then replace with the total of every
    By CharlieAziz in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-03-2012, 11:08 PM
  3. [SOLVED] Return specific values based on the range in another cell
    By AndrewBondarchuk in forum Excel General
    Replies: 3
    Last Post: 11-28-2012, 12:34 PM
  4. Replies: 2
    Last Post: 11-21-2012, 05:59 AM
  5. Open .TXT file Replace Specific Lines with Cell Values
    By Tellm in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-09-2011, 12:08 PM

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