+ Reply to Thread
Results 1 to 2 of 2

VBA: Drag Down Formula To Last Row Number of a Different Column

Hybrid View

  1. #1
    Registered User
    Join Date
    02-14-2017
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    19

    VBA: Drag Down Formula To Last Row Number of a Different Column

    I am just a beginner with VBA so pardon me in advance for the simple question.

    I have a VBA that pastes the formula to columns that are non-contiguous.
    Sub FillFormula()
        Range("XET3").Formula = "=TRIM(RC[1])&TRIM(RC[2])&"",""&TRIM(RC[3])"
        Range("XEU3").Formula = "=TEXT(RC4,""Mmm"")"
        Range("XEV3").Formula = "=DAY(RC4)"
        Range("XEW3").Formula = "=YEAR(RC4)"
        Range("XEZ3").Formula = "=IF(TRIM(LEFT(RC[-1],4))=""9999"",""no"",""yes"")"
        Range("XFA3").Formula = "=IF(RC[-1]=""yes"",(DATE((LEFT(RC[-2],4)),(MID(RC[-2],6,2)),(RIGHT(RC[-2],2))))-(DATE((LEFT(RC[-3],4)),(MID(RC[-3],6,2)),(RIGHT(RC[-3],2)))),"""")"
        Range("XFB3").Formula = "'=IFERROR(IF(AND(XFA3>=30,XEZ3=""yes""),1,0),0)"
        Range("XFD3").Formula = "'=TEXT((MONTH(D3)&""/""&DAY(D3)&""/""&YEAR(D3)),""Mmm"")&RIGHT(YEAR((MONTH(D3)&""/""&DAY(D3)&""/""&YEAR(D3))),2)"
    End Sub

    I need a VBA code that would drag down all these formula based on the last row of Column D.
    I wrote it as:
    Sub FillDown()
    Dim lastRow As Long
    lastRow = Range("D" & Rows.Count).End(xlUp).Row
    Range("XET3").Copy
    Range(Cells(3, 16374), Cells(lastRow, 16374)).PasteSpecial (xlPasteFormulas)
    End Sub
    But this would do it column by column. Is there a way to simplify this?
    Thanks!
    Last edited by lb0389; 06-29-2017 at 07:19 AM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA: Drag Down Formula To Last Row Number of a Different Column

    Please apply Code Tags
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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. Drag formula where sheet name (number) is variable
    By duszek00 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-13-2014, 12:57 AM
  2. Use formula to drag across but skip n number of cells
    By excelas88 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-14-2013, 09:59 PM
  3. Drag down Formula for specific number of Rows
    By sathyasun in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2013, 08:46 AM
  4. Vlookup but change column index number as you drag to next column
    By yankeekid86 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-29-2013, 09:46 AM
  5. [SOLVED] Drag down formula to skip a large number of rows
    By exclaymation in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-19-2013, 11:23 PM
  6. How to drag a formula increasing tab number only?
    By Ba1ley in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 04-22-2013, 01:26 PM
  7. [SOLVED] Identify the last filled row in Column A and then drag formula in Column B till the same
    By bonny24tycoon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2012, 10:50 AM

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