+ Reply to Thread
Results 1 to 14 of 14

Dynamic Range of Columns with fixed Rows

  1. #1
    Registered User
    Join Date
    06-16-2008
    Location
    Arlington, VA
    MS-Off Ver
    2007
    Posts
    93

    Dynamic Range of Columns with fixed Rows

    I am still trying to develop a macro that will copy and paste a set of formulas into a dynamic destination range. I have included a worksheet that shows what I am trying to do. Basically when using AutoFill I need the columns of the destination range to be dynamic based on the number of rows in another sheet.
    Please Login or Register  to view this content.
    So if the number of rows is determined by a COUNTA formula that returns a result of 3, the destination range will be "D42:F68", if 94 , "D42:CS68".
    Also I would like to change the Selection to be a fixed named range such as "ACCT".

    Is this possible?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    There is no attachment
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-16-2008
    Location
    Arlington, VA
    MS-Off Ver
    2007
    Posts
    93

    Missing attachment

    I apologize. The attachment should be included now. It is very simplistic, but I think it helps to explain my goal.
    Attached Files Attached Files

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    It's still not clear what you want.

  5. #5
    Registered User
    Join Date
    06-16-2008
    Location
    Arlington, VA
    MS-Off Ver
    2007
    Posts
    93

    Dynamic Range for Macro

    I am trying to define a dynamic range in the macro, either for a copy and paste or an auto fill macro. I cannot figure out how to make the ranges variable in the macro, rather than fixed.
    The number of columns to paste across is currently determined by a COUNTA formula that is counting the number of rows with information on another sheet. For instance if I have formulae in range A1:A15 and in another column I have data in 10 rows, the macro will copy A1:A15 and paste the formulae into B1:J15.
    J is determined as being the 10th column.
    The problem is making the Range("_:_") part of the macro dynamic.

    Any ideas?

    Thanks for your patience.

  6. #6
    Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    An hour due East of Cowtown Ohio
    MS-Off Ver
    2010
    Posts
    421
    I changed your example spreadsheet a bit - to make your NUMBER OF COLUMNS data not in the same rows of where the formulas where being copied to.

    I created a macro TEST that copies and INSERTS the over the number of columns to the right of the originating FORMULA range for the number of rows found in your NUMBER OF COLUMNS data range. Note this is inserting the text...however you can tweek it for formulas
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    06-16-2008
    Location
    Arlington, VA
    MS-Off Ver
    2007
    Posts
    93

    Question

    What are the 5 and 3 referring to?

    Range(Cells(5, 3)

  8. #8
    Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    An hour due East of Cowtown Ohio
    MS-Off Ver
    2010
    Posts
    421
    Quote Originally Posted by nms2130 View Post
    What are the 5 and 3 referring to?

    Range(Cells(5, 3)
    "Cells(5,3)" refers to 5th row, 3rd column - otherwise known as C5. I did it in the R1C1 format so you can make the Range dynamic..

  9. #9
    Registered User
    Join Date
    06-16-2008
    Location
    Arlington, VA
    MS-Off Ver
    2007
    Posts
    93

    Question 2

    I understand now. Is it possible to have the copied range pasted over the selected range? When inserting as it is, an error is returned because it is pushing cells off of the sheet.

  10. #10
    Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    An hour due East of Cowtown Ohio
    MS-Off Ver
    2010
    Posts
    421
    Please Login or Register  to view this content.
    I changed the last two lines of code...

    Note...if you were originally getting an error message for pushing cells off the sheet...you might have data that was in those cells that was triggering the message. With that being said....you potentially have the issue of those cells being written over with a paste functionality if it copies that many columns over.
    Last edited by GuruWannaB; 01-05-2009 at 04:51 PM. Reason: Fixed code error

  11. #11
    Registered User
    Join Date
    06-16-2008
    Location
    Arlington, VA
    MS-Off Ver
    2007
    Posts
    93
    Error
    Object doesn't support this property or method
    Range(Cells(42, 4), Cells(15, Srange)).Paste

  12. #12
    Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    An hour due East of Cowtown Ohio
    MS-Off Ver
    2010
    Posts
    421
    My mistake...review the code again above...I corrected it

  13. #13
    Registered User
    Join Date
    06-16-2008
    Location
    Arlington, VA
    MS-Off Ver
    2007
    Posts
    93

    Fantastic

    This is great! Thank you, it is working great now!

  14. #14
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Please edit you're post to include code tags as per forum rules below

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ 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