Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:33:38+00:00 2026-06-11T07:33:38+00:00

Right now, I’m creating a new workbook with 12 column names all in row

  • 0

Right now, I’m creating a new workbook with 12 column names all in row 1 and every time I run my macro to test it, the workbook has a different name (Book1, Book2,….)

I want to get specific columns from a CLOSED workbook and paste them to different columns in this new workbook. I do NOT want to use the GetValuesFromAClosedWorkbook because in my macro, the user is picking the file (“Y:…\Test.xls”).

I have the following code which works, but is not as automated as I would like it to be because I will not know the name of the workbook…whether if it’s Book1, Book2, and so on…AND because it’s opening the file, which I don’t want it to do.

Workbooks.Open Filename:="Y:\......\Test.xls"
Range("D3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("Book1").Activate
ActiveWorkbook.ActiveSheet.Range("B2").PasteSpecial Paste:=xlValues   

Is it possible that once the user picks the file, I can pick certain columns and paste them to this new workbook?

Any help will be appreciated!
Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:33:40+00:00Added an answer on June 11, 2026 at 7:33 am

    When you open a workbook you can do this:

    Dim wb as WorkBook
    Set wb = Workbooks.Open("filepathhere")
    

    Or when you add a new workbook:

    Set wb = Workbooks.Add()
    

    You can then use the reference wb:

    Dim rngCopy as Range
    Set rngCopy = wb.Sheets(1).Range(.Range("D3"), .Range("D3").End(xlDown))
    
    wb2.Sheets("sheetname").Range("B2").Resize(rngCopy.Rows.Count).Value = rngCopy.Value
    

    Where wb is the file you opened and wb2 is the newly-added workbook.

    Using a “helper” sub to perform the copying:

    Sub DoCopy(rngFrom as Range, rngTo as Range)
        Dim rngCopy as Range
        Set rngCopy = rngFrom.Parent.Range(rngFrom,rngFrom.End(xlDown))
        rngTo.Resize(rngCopy.Rows.Count).Value = rngCopy.Value
    End Sub
    

    If you want to copy both values and formats:

    Sub DoCopy(rngFrom As Range, rngTo As Range)
        rngFrom.Parent.Range(rngFrom, rngFrom.End(xlDown)).Copy
        rngTo.PasteSpecial xlPasteFormats
        rngTo.PasteSpecial xlPasteValues
    End Sub
    

    Usage:

    'updated to copy values to first empty row (NOTE: all copied columns
    '   must be the same length)
    Dim shtDest as Worksheet
    Set shtDest= wb2.Sheets("sheetname")
    
    DoCopy wb.Sheets(1).Range("D3"), shtDest.Cells(.Rows.Count, 2).end(xlUp).offset(1,0)
    DoCopy wb.Sheets(1).Range("G3"), shtDest.Cells(.Rows.Count, 3).end(xlUp).offset(1,0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now when I run this it keeps clicking on the same button every
Right now any new UIViewController added to my storyboard needs to have a class
Right now I have the following query: User.find(:all, :conditions => [guest = ? AND
Right now I'm doing this: class MyTest(Base): __tablename__ = 'mytest' id = Column(Integer, primary_key
Right now I've been maintaining a second sandbox project where I test concepts and
Right now I'm using the following command to compile a coffeescript file each time
Right now I'm using OleDbDataAdapter objDataReader = new OleDbDataAdapter(); objDataReader.SelectCommand = myCommand; objDataReader.Fill(myDataTable); But
Right now, I do this: try: blah except Exception, e: print e time.sleep(9999) Instead
right now I have a keyboard macro defined and named, and i want to
Right now we have a dll file that contains all the database calls and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.