+ Reply to Thread
Results 1 to 3 of 3

Thread: Applying a formula to a column

  1. #1
    Registered User
    Join Date
    06-29-2011
    Location
    MUMBAI
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    37

    Applying a formula to a column

    I am new to macro and will like to know how to apply a formula to an entire column and wat is its code.
    I want to apply formula to column AR and it goes,
    =sumif(I:I,I2,N:N)
    the formula has to start from 2nd row coz first ow wld contain a heading.
    how shld i apply it.
    any help would be appreciated
    Thanks in advance
    REGARDS,
    VIPUL
    Last edited by vipul.halbe; 07-04-2011 at 04:19 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    2007
    Posts
    933

    Re: Applying a formula to a column

    Hi Vipul,

    Try this:

    Sub Macro1()
    
        Dim lngLastRowColI As Long, _
            lngLastRowColN As Long
            
        lngLastRowColI = ActiveSheet.Cells(Rows.Count, "I").End(xlUp).Row
        lngLastRowColN = ActiveSheet.Cells(Rows.Count, "N").End(xlUp).Row
        
        If lngLastRowColI >= lngLastRowColN Then
            ActiveSheet.Range("AR2:AR" & lngLastRowColI).Formula = _
                "=SUMIF($I$2:$I$" & lngLastRowColI & ",I2,$N$2:$N$" & lngLastRowColI & ")"
        Else
            ActiveSheet.Range("AR2:AR" & lngLastRowColN).Formula = _
                "=SUMIF($I$2:$I$" & lngLastRowColN & ",I2,$N$2:$N$" & lngLastRowColN & ")"
        End If
    
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    06-29-2011
    Location
    MUMBAI
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    37

    Re: Applying a formula to a column

    It works beautifully
    Thanks
    Regards
    Vipul

+ 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.2.0