+ Reply to Thread
Results 1 to 2 of 2

Insert a formula if there is a value on a cell in the same row

Hybrid View

  1. #1
    Registered User
    Join Date
    10-09-2012
    Location
    florida
    MS-Off Ver
    Excel 2003
    Posts
    11

    Insert a formula if there is a value on a cell in the same row

    I need to get a macro that if a row has any value on column D, it creates a formula in column A, another formula in B, and another formula in C.

    Column A's formula is =VALUE(RIGHT(D6,7))
    Column B's formula is =CONCATENATE(D6,"_",TEXT(COUNTIF(D$4:$D6,D6),"000"))
    Column C's formula is =CONCATENATE(D6,"_",G6)

    Also, it needs to ignore rows 1,2,and 3 as the data starts on row 4.

    Entering all these formulas as a template takes up a lot of space in the file since the data could be 300 rows or 30,000 depending on the day. This is why I need a macro so the formulas are only entered when there is a value that needs them.


    Can you please help??

    Thank you!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Insert a formula if there is a value on a cell in the same row

    Try the below code...

    Change the Start and EndRw Values to your desired rows.

    Sub AddFormulasAndConvertItAsValues()
    Dim iStartRw As Integer, nEndrw As Long
    
    iStartRw = 6
    nEndrw = 35000
    
    Range("A" & iStartRw & ":" & "A" & nEndrw).Formula = "=VALUE(RIGHT(D6,7)"
    Range("B" & iStartRw & ":" & "B" & nEndrw).Formula = "=CONCATENATE(D6,""_"",TEXT(COUNTIF(D$4:$D6,D6),""000""))"
    Range("C" & iStartRw & ":" & "C" & nEndrw).Formula = "=CONCATENATE(D6,""_"",G6)"
    
    Range("A" & iStartRw & ":" & "C" & nEndrw).Value = Range("A" & iStartRw & ":" & "C" & nEndrw).Value
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

+ 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