+ Reply to Thread
Results 1 to 28 of 28

Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

  1. #1
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    I have created a loop to create new columns until there is not next in the next columns. However I am trying to include a formula in this loop and I cannot get the drag down to be based on the active column. Right now i have:

    ActiveCell.Select
    Selection.Copy
    Selection.AutoFill Destination:=Range("D5:D226")
    Range("D5:D150").Select

    I want the Range to be something like ("Activecell.Column:ActiveCell.Column"). I have also tried Range("5:150)" to capture only the rows I want my formula filled to, but that doesn't work. The goal is that I can use the loop to drag the formula down all columns with an active formula without having to alter every single column (which won't work because this will be used on data with different amounts of columns).

    I have tried searching a bunch of forums but have not found anything like this.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Does this help?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    I get the following error:
    Run-time error '1004': You cannot change part of an array
    Sorry, I forgot you cannot edit an array...is there a workaround for that?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Can you attach a sample sheet? That way we can see what's going on.

  5. #5
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    For privacy reasons I cut out unnecessary information.

    Dim x As Long
    x = Cells(Rows.Count, ActiveCell.Column).End(3).Row
    Selection.FormulaArray = _
    "=INDEX(Data!R1C8:R1000000C8,SMALL(IF(R2C2=Data!R[-4]C3:R1000000C3,ROW(Data!R[-4]C3:R1000000C3)-MIN(ROW(Data!R1C3:R1000000C3))+1,""""),ROW(Data!R[-4]C3)))"
    ActiveCell.Copy Range(Cells(2, ActiveCell.Column), Cells(x, ActiveCell.Column))
    Attached Files Attached Files
    Last edited by KAP123; 11-07-2016 at 04:00 PM.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    It works for me on the sample you sent, but I notice that your formula is not active (no = sign). Can you amend where the formula is active?

  7. #7
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    I'm not sure what you mean, there is an "=" before INDEX ?

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    On your sample the cell in B4 has a formula but no "=" sign at the beginning. The code works for me with that cell. Is that the one you are referring too? When I insert the "=" it says the formula itself contains an error? I'm not that good with formula, and I cannot interpret what is causing the error.
    Last edited by JOHN H. DAVIS; 11-07-2016 at 04:40 PM.

  9. #9
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Oh that is the formula I have for when I was writing the macro so I didn't copy and paste the code.

    Dim x As Long
    x = Cells(Rows.Count, ActiveCell.Column).End(3).Row
    Selection.FormulaArray = _
    "=INDEX(Data!R1C8:R1000000C8,SMALL(IF(R2C2=Data!R[-4]C3:R1000000C3,ROW(Data!R[-4]C3:R1000000C3)-MIN(ROW(Data!R1C3:R1000000C3))+1,""""),ROW(Data!R[-4]C3)))"
    ActiveCell.Copy Range(Cells(2, ActiveCell.Column), Cells(x, ActiveCell.Column))

    This is what my code looks like right now. Perhaps I have it in the wrong order? I currently have it set up in D5 but it should work the same as B5.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    I have to run for now. It's my end of day. If no one else jumps in I will take another look tomorrow morning.

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    What are you selecting for the formula? Is it more than one cell? Again, I get an error on the formula itself, when I try to place it on the sheet. Can you provide a sample where it is already there?

  12. #12
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Does this help?
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Yes it does, and it works for me. If you take the code I gave you and redefine x to a specific row then it places the formula down Column D. Try it. Select D5 and run the code.

    Please Login or Register  to view this content.
    Last edited by JOHN H. DAVIS; 11-08-2016 at 11:22 AM.

  14. #14
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    I'm still getting the hang of VBA. Which part of the "x = ..." would I change?
    I tried:

    x = Cells(Rows.Count, ActiveCell.Column).End(3).150

    x = Cells(Rows.Count, ActiveCell.Column).End(150).row

    x = Cells(150, ActiveCell.Column).End(3).row

    x = Cells(150.Count, ActiveCell.Column).End(3).row

    x = Cells(Rows.150, ActiveCell.Column).End(3).row

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    I changed it for you in Post 13 for testing. You can't use Activecell.Column from your sample because it only goes too row 3, which is where the activecell is.

  16. #16
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    When I download the example spreadsheet and run the macro it works. However in my original spreadsheet it doesn't, it says can't alter array. Any idea why this might be?

  17. #17
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    I got the same error when I didn't change x. You need to indicate what the last row is in the macro. You can't use Activecell.Column because the row number is 3. Try using x = Activesheet.UsedRange.Rows.Count instead. Let me know how you come out.

  18. #18
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Same error

  19. #19
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Run this and let me know what x reads.

    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    It came up as 225

  21. #21
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    It should work without error. I'm afraid I can't be of any more help. I'd have to see the original worksheet. If it worked on the sample it should work on the original.

  22. #22
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Okay..thank you for your help!

  23. #23
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Here is the original
    Attached Files Attached Files

  24. #24
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Try:

    Please Login or Register  to view this content.
    Note: The change in the fill-down range. Activecell should be D5.

  25. #25
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    It works!! So it was selecting the wrong cell to pull down from because of that?

  26. #26
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Yep. It was trying too change the activecell which had the formula. Therefore the reason for the error.

  27. #27
    Registered User
    Join Date
    11-07-2016
    Location
    Indianapolis, Indiana
    MS-Off Ver
    2010
    Posts
    36

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    Thank you for the help and explanation!

  28. #28
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Excel 2010-VBA: Trying to create a filldown that is based on the current/active column

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. Print current page with active cell with VBA code Excel 2010
    By ruznemat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2017, 08:42 AM
  2. Highlighting row and column of active cell (Excel 2010)
    By Smiffy3594 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2015, 11:44 AM
  3. Replies: 1
    Last Post: 07-23-2014, 04:33 AM
  4. EXCEL 2010 create a macro- highlight any cells with more than 30 characters in a column
    By cluelessexcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2013, 11:00 AM
  5. Using VBA to insert current active VBA based webbrowser into Excel spreadsheet
    By heolink2006 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2013, 02:10 AM
  6. VBA - Can I select a new active cell based on the value of the current active cell?
    By GrumpyOldBastard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2012, 07:05 PM
  7. FillDown only Filtered Active Cells
    By izet99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2009, 09:32 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