+ Reply to Thread
Results 1 to 3 of 3

Match text then enter formula

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Match text then enter formula

    I would like to check the text in the first column of a named range.
    If Text in the cell above = current selected cell then, add a formula to
    (same Row, column D) where that formula would take the value of the cell above.
    Something like: (Row, col D) = (Row -1, col D)

    I believe a For loop is required. I just don't know how to cycle through the cells in Col A
    and then put the formula in Col D.

    Thanks for any help!

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Match text then enter formula

    Hello,

    Something like that ???

    Sub test()
        Dim rg As Range, c As Range
        
        Set rg = Range("A2:A10")   'define range here
        
        For Each c In rg
            If c.Offset(-1, 0).Value = c.Value Then c.Offset(0, 3).Formula = c.Offset(-1, 3).Formula
        Next c
    
    End Sub
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Re: Match text then enter formula

    Quote Originally Posted by GC Excel View Post
    Hello,

    Something like that ???

    Sub test()
        Dim rg As Range, c As Range
        
        Set rg = Range("A2:A10")   'define range here
        
        For Each c In rg
            If c.Offset(-1, 0).Value = c.Value Then c.Offset(0, 3).Formula = c.Offset(-1, 3).Formula
        Next c
    
    End Sub
    Thanks GC!
    Your code is almost what I am looking for.
    Right now your code is putting in values into column D.
    I would like to put in formulas instead; like =(D30) etc. (My range is A30:A55)
    The formulas should be relative to the cell above, so one cell would be
    =(D30) another cell would be =(D31) etc.

    Just to be clear, it might look like this:
    AAA 44
    AAA =(D30)
    AAA =(D31)
    BBB 26
    BBB =(D33)
    BBB =(D34)
    Last edited by ChrisXcel; 03-30-2014 at 08:15 PM.

+ 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. [SOLVED] Enter formula only if a cell does not contain specific text
    By lday75 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-24-2013, 01:45 PM
  2. Replies: 3
    Last Post: 09-20-2013, 04:24 PM
  3. Match text in A1 to a part of a text string in B1 and enter data D1
    By markDuffy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-30-2013, 10:16 PM
  4. Enter text into a formula using VBA
    By dgtvr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-06-2008, 10:13 AM
  5. Enter a Formula along with the text
    By shabeerbash in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 03-24-2007, 09:41 AM

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