+ Reply to Thread
Results 1 to 28 of 28

Copying columns

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Copying columns

    Hi

    Does anyone know where it is possible to use a counta result in sheet1 to determine how many columns Column A should copied and autofilled over in macro?

    Thanks

    Jeskit
    Last edited by jeskit; 02-08-2011 at 11:07 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    I'm sure it might be possible but I'm not sure it's necessary.

    If you can describe your problem, maybe with a sample workbook there's probably another way of doing what you want.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Hi

    Well the problem is i have a macro inside workbook 1 which opens workbook2. It thens loops through a folder and copies column e from each of the files which are on a list in workbook2 sheet 3 and pastes into sheet1 of workbook2 in a new column.

    However in sheet2 of workbook2 i have a column full of formula. Also in Sheet 3 with the list is a macro which does a counta on that list. What i need to do is in the macro add a bit of code which takes the counta result and uses it to copy the forumla across that number (counta result) of columns.

    Sorry i cant put a workbook as it has sensitive data in it.

    Hope this helps.

    Jeskit

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    Are you getting columns and rows mixed up in your description?

    Here's an example of how you can populate a column with formula based on a variable length list:

    Please Login or Register  to view this content.

    This fills column C2 downwards based on the number of rows of data in column A.

    I've attached a sample.

    Dom
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Hi

    I have added a template of my workbook. In sheet 1 is a list with a counta in cell H1.

    I need to use the result of the counta in cell H1 to determine how many columns i need copy all the formula in Column E in the ExtractReport sheet and auto ill into.

    Does this make more sense?

    Thanks

    Jeskit
    Attached Files Attached Files

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    So you want to copy the formula from column E on the ExtractReport sheet and paste it down the list in column E on Sheet1?

    The formula in column E doesn't seem to be consistent which is a bit confusing.

    Also you appear to still have a lot of data in your sample that's 'hidden' with a white font. I hope that's not the sensitive data you were talking about.

    Dom

  7. #7
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    No what i want to do is do an auto fill using the forumla in column E on sheet ExtractReport and copy it along the columns in the ExtractReport sheet. But i need to use the counta result to determine how many columns i need to do teh autofill for.

    There is a different forumla in each cell in column E but i need all the forumlas to be autofilled.

  8. #8
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Currently i am using this piece of code
    Please Login or Register  to view this content.
    But that just uses a selected destination, however i need change this so it determines the destination columns based on the number provided by the counta

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    Got you, being a bit slow today.

    Try this:

    Please Login or Register  to view this content.

    Dom

  10. #10
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    hI

    I tried your code and it produced an error. it said "Application defiend or object defiend error"

  11. #11
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    It should work on the sample you provided.

    Are your sheets named the same on the workbook you tried it on?

    Dom

  12. #12
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Yep all the same

  13. #13
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    I've attached the workbook with the code that works for me.

    Dom
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    OK had a look tried it again and i am still getting an error. Question what excel are you using as i am using 2010?

  15. #15
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    I'm using 2003 but pretty sure there's nothing in that code that won't work in later versions.

    It doesn't work in the sample I just posted?

    Dom

  16. #16
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Also i am not running the code in the same workbook. The macro is being run from another workbook which acts as only a home for the macro.

    My macro opens the template workbook and then runs the code to perform the count a in cell H1 and then performs the autofill.

    I have pasted the code below if that helps:

    Please Login or Register  to view this content.

  17. #17
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    no it worked in the sample you sent me but it doesn' work in mine

  18. #18
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Copying columns

    Try this:

    Please Login or Register  to view this content.

    Dom

  19. #19
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Nope still not working still getting "Application defined or object defined error"

  20. #20
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Copying columns

    Looking back no further than Domski's last post, maybe

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  21. #21
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Hi

    Ok that works but doesn't do what i need it to. I need to do that for a defined numebr of columns. The number of columns is the result of the counta

  22. #22
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    What i need is for it to do this
    Please Login or Register  to view this content.
    But instead of using the
    Please Login or Register  to view this content.
    i need it to do this but for the numebr of columns defined in the result of the counta

  23. #23
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Copying columns

    Maybe

    Please Login or Register  to view this content.

  24. #24
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Sorry it still produces an Application defined or object defined error

  25. #25
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    However i might have done the end bit wrong how to get it to look at the cell with counta result?

    currently i have this, which could be wrong,
    Please Login or Register  to view this content.

  26. #26
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Copying columns

    You're resizing columns
    Please Login or Register  to view this content.

  27. #27
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Still getting the error message application defined or object defined error

  28. #28
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Copying columns

    Hi

    Found the problem i had accedently deleted the counta forumla..fixed now!!!!

    Thank you All for you help

    I am extremely gratefull

    THANKS

+ 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