+ Reply to Thread
Results 1 to 7 of 7

Find Last Cell with Data and Drag that Formula Down

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2014
    Location
    Not of this world
    MS-Off Ver
    Excel 2013
    Posts
    37

    Find Last Cell with Data and Drag that Formula Down

    Hello,

    I am trying to find the last cell in column B which is in Row 10000+ and copy the formula down to the last cell based on Column A's last row. Here is what I'm starting with:

    Dim lastRow, dragRange as Long
    lastRow = Range("B2").End(xlDown).Row
    dragRange = Range("A2").End(xlDown).Row
    I know how to drag a formula down based on a fixed cell such as:

    Dim dragRange As Long
    dragRange = Range("B2").End(xlDown).Row
    Range("A2").AutoFill Destination:=Range("A2:A" & dragRange), Type:=xlFillValues
    But, I don't know how to drag a formula down when the cell is not fixed. I don't want to AutoFill any rows above, just B10000 (or whatever the row is at the time) and below. Any help would be greatly appreciated.

    Thank you in advance for your time.

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Find Last Cell with Data and Drag that Formula Down

    Perhaps like this:
    Sub TerFuge()
    
    Dim lngBLR As Long: lngBLR = Range("B" & Rows.Count).End(xlUp).Row
    Dim lngALR As Long: lngALR = Range("A" & Rows.Count).End(xlUp).Row
    Range("B" & lngBLR & ":B" & lngALR).FillDown
    
    End Sub
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    03-06-2014
    Location
    Not of this world
    MS-Off Ver
    Excel 2013
    Posts
    37

    Re: Find Last Cell with Data and Drag that Formula Down

    Quote Originally Posted by daffodil11 View Post
    Perhaps like this:
    Sub TerFuge()
    
    Dim lngBLR As Long: lngBLR = Range("B" & Rows.Count).End(xlUp).Row
    Dim lngALR As Long: lngALR = Range("A" & Rows.Count).End(xlUp).Row
    Range("B" & lngBLR & ":B" & lngALR).FillDown
    
    End Sub
    Thank you for the quick response but the code does not drag the formula down to the last row in Column A. All it does is update the formula in Column B's last cell. Any ideas?

  4. #4
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Find Last Cell with Data and Drag that Formula Down

    ni nva2k4,

    you may change dragRange from bottom to top.

    dragRange = Cells(Rows.Count, "B").End(xlUp).Row
    1. Thank those who have helped you by clicking the Star * below the post.
    2. Please mark your post [SOLVED] if it has been answered satisfactorily.

    Sincerely,
    Farid

  5. #5
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Find Last Cell with Data and Drag that Formula Down

    I'd recommend attaching an example of your work. It works just dandy in my version.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-06-2014
    Location
    Not of this world
    MS-Off Ver
    Excel 2013
    Posts
    37

    Re: Find Last Cell with Data and Drag that Formula Down

    Quote Originally Posted by daffodil11 View Post
    I'd recommend attaching an example of your work. It works just dandy in my version.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).
    daffodil11,

    Your code did work as you said. I am not really working with Columns A & B in my code; therefore, when I pasted your code in mine and changed the variable names and Ranges accordingly, I was using the wrong column for the Fill Range.

    Thanks for your expertise, it's working great now!

  7. #7
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Find Last Cell with Data and Drag that Formula Down

    No problem. Glad I could help.

+ 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] Drag formula to every second cell
    By jojo101 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-23-2015, 11:23 AM
  2. Drag cell formula down as far as the data range goes with VBA
    By mike_980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-02-2014, 06:02 AM
  3. How to drag formula of every other cell
    By sasiddiq in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-14-2014, 05:51 PM
  4. [SOLVED] Drag cell formula for paired data
    By Phily915 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-11-2014, 01:09 PM
  5. [SOLVED] Drag a formula that references a cell from another Sheet (Skipping a cell incrementing 1)
    By DixieDiver in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-05-2013, 06:25 PM
  6. [SOLVED] Find the Max and Time then drag formula
    By JDCONNER in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-05-2013, 02:30 PM
  7. data validation-drag the formula down
    By frenchboy in forum Excel General
    Replies: 4
    Last Post: 05-28-2011, 10:33 PM

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