Results 1 to 11 of 11

Vba code to update a cell value based on its current value and another cells value

Threaded View

  1. #1
    Registered User
    Join Date
    06-07-2013
    Location
    Troy, MI
    MS-Off Ver
    Excel 2007
    Posts
    5

    Vba code to update a cell value based on its current value and another cells value

    Hello Excel Forum--this is my first post on this site although I've used this site many times. I need a code that can find a specific value in a specific column and once that value is found, look at another column in the same row for a specific value. If both values are found, update the first value found with a specific value. For example;

    I have data filled in all cells range (A1:C100). Look in Column A for the value "Apples", Say "Apples" is the value of cell A13. Then look at C13 to see if it has the value of "005". If it does not, then do nothing. If it does, then update cell A13 with the value "Apples 005". Then continue the process through the end of Column A.

    Here is the code I have tried to work with:

    Sub Test()

    Set target = Sheets("Sheet1").Range("A:A")
    Set target1 = Sheets("Sheet1").Range("C:C")

    For Each cell In target1

    If cell.Value = "005"

    Then

    For Each cell In target

    If cell.Value = "Apples"
    cell.Value = "Apples 005"

    End If

    Next cell




    End Sub


    I know how to make this code work for one condition but not for two conditions. I have similar restriction issues with the following code:


    Sub Test1()



    If Range("A13").Value = "Apples" And Range("C13").Value = "005" Then
    Range("A13").Value = "Apples 005"

    End If

    End Sub

    This is good if I always knew the location of the value of "Apples", but I do not. I only know the Column and value. Any help on this will be much appreciated, as I search this site for similar issues but have not found any. Also, I can make this work via a formula but I prefer a to stick with a VBA macro.


    Thank you!
    Last edited by g.h0st.snwbrd3r; 06-07-2013 at 02:06 PM.

Thread Information

Users Browsing this Thread

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

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