+ Reply to Thread
Results 1 to 4 of 4

Modifying code to Consolidate only 1 column..

  1. #1
    Darin Kramer
    Guest

    Modifying code to Consolidate only 1 column..

    Hi there,

    The code below correctly opens however many excel workbooks located
    within a sub directory, and copies and pastes the first 4 columns into
    another sheet. (end result is you have consolidated the 4 columns into
    new sheet)

    QUESTION I
    I want to modify the code ONLY to copy column 2 into the new sheet, (and
    do repetively for all books within the same sub directory) How do I do
    so...? (My VB skills are slightly limited.., so not sure which variable
    to change....)

    Question II
    Is there any way to turn off the auto alert when you open a book that
    says "Do you want to enable Macros", and the auto alert when you close
    the book that says "there is a large amount of data on the clipboard, do
    you want it available for later use...?

    Thanks!!!!
    Regards

    Darin

    Sub Consolidator

    Dim i As Long, sName As String, sh As Worksheet
    Dim dest As Range, bk As Workbook
    i = 1
    sName = Dir("D:\Documents and
    Settings\user\Desktop\Projects\Projects_06\Consolidation_test\results\*.
    xls")
    Do While sName <> ""
    Set bk = Workbooks.Open("D:\Documents and
    Settings\user\Desktop\Projects\Projects_06\Consolidation_test\results\"
    & sName)
    Set sh = bk.Worksheets("Answers")
    Set dest = ThisWorkbook.Worksheets(1).Cells(1, i)
    i = i + 1
    sh.Columns(1).Resize(, 2).Copy
    dest.PasteSpecial xlValues
    dest.PasteSpecial xlFormats
    ' write name of the workbook in row 1
    dest.Value = sName
    ' close the workbook
    bk.Close SaveChanges:=False
    sName = Dir()
    Loop
    ActiveSheet.Select
    ActiveSheet.Name = "Consolidated"



    End Sub

    *** Sent via Developersdex http://www.developersdex.com ***

  2. #2
    Bob Phillips
    Guest

    Re: Modifying code to Consolidate only 1 column..

    Looks like 2 columns to me.

    Change this

    sh.Columns(1).Resize(, 2).Copy

    to

    sh.Columns(2).Copy


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Darin Kramer" <[email protected]> wrote in message
    news:[email protected]...
    > Hi there,
    >
    > The code below correctly opens however many excel workbooks located
    > within a sub directory, and copies and pastes the first 4 columns into
    > another sheet. (end result is you have consolidated the 4 columns into
    > new sheet)
    >
    > QUESTION I
    > I want to modify the code ONLY to copy column 2 into the new sheet, (and
    > do repetively for all books within the same sub directory) How do I do
    > so...? (My VB skills are slightly limited.., so not sure which variable
    > to change....)
    >
    > Question II
    > Is there any way to turn off the auto alert when you open a book that
    > says "Do you want to enable Macros", and the auto alert when you close
    > the book that says "there is a large amount of data on the clipboard, do
    > you want it available for later use...?
    >
    > Thanks!!!!
    > Regards
    >
    > Darin
    >
    > Sub Consolidator
    >
    > Dim i As Long, sName As String, sh As Worksheet
    > Dim dest As Range, bk As Workbook
    > i = 1
    > sName = Dir("D:\Documents and
    > Settings\user\Desktop\Projects\Projects_06\Consolidation_test\results\*.
    > xls")
    > Do While sName <> ""
    > Set bk = Workbooks.Open("D:\Documents and
    > Settings\user\Desktop\Projects\Projects_06\Consolidation_test\results\"
    > & sName)
    > Set sh = bk.Worksheets("Answers")
    > Set dest = ThisWorkbook.Worksheets(1).Cells(1, i)
    > i = i + 1
    > sh.Columns(1).Resize(, 2).Copy
    > dest.PasteSpecial xlValues
    > dest.PasteSpecial xlFormats
    > ' write name of the workbook in row 1
    > dest.Value = sName
    > ' close the workbook
    > bk.Close SaveChanges:=False
    > sName = Dir()
    > Loop
    > ActiveSheet.Select
    > ActiveSheet.Name = "Consolidated"
    >
    >
    >
    > End Sub
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  3. #3
    Darin Kramer
    Guest

    Re: Modifying code to Consolidate only 1 column..


    Thanks Bob - works great. Any ideas for Question II ?


    *** Sent via Developersdex http://www.developersdex.com ***

  4. #4
    Bob Phillips
    Guest

    Re: Modifying code to Consolidate only 1 column..

    You cannot stop them getting that message without setting your security
    setting to low (which is a very bad idea), but you can take some defensive
    action.

    You can digitally sign the workbook so they don't get the message, or you
    can try and make the workbook (seemingly) inoperable if the users disable
    macros.

    The standard way to approach this is as follows.
    - create a worksheet with a message on explaining that for this workbook to
    run it needs macros enabled, maybe even a few screenshots
    - hide all other worksheets]
    - add some code in the Workbook_Open event that un hides the other sheets,
    but hides that sheet.


    What happens is that if they do not enable macros, they will only see the
    warning sheet, telling them how to do it. If the enable macros, it will
    startup as the workbook it should be.


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Darin Kramer" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Thanks Bob - works great. Any ideas for Question II ?
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




+ 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