+ Reply to Thread
Results 1 to 8 of 8

Need help with copy and paste VBA code

  1. #1
    Registered User
    Join Date
    04-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    84

    Post Need help with copy and paste VBA code

    I have the following code which I got to work, copying a range from one workbook to another.

    Please Login or Register  to view this content.
    the problem I have is that I have to copy the same range from file "A (Shelby). ex:04.11.17 Shelby.xlsx, 04.12.17 Shelby.xlsx, etc) into file "B" Consolidated into a new range.

    is there a way to copy the Range from file "A" (B8;F21) to the new desire Range?

    File A Is a file that I have to open from the cloud (not on my local drive) but one file is open I got the code to work. just need to know how to copy same range to my consolidated file.

    Let me know if you need sample of file.

    thank you

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Need help with copy and paste VBA code

    assuming you are running the code while file "A" is open and active
    you can replace Workbooks("04.10.17 SHELBY.xlsx") with thisworkbook
    ie
    Please Login or Register  to view this content.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Need help with copy and paste VBA code

    Hi humdingaling,

    I replied but I don't why it didn't post. anyhow, I tried using replacing "Thisworkbook.Worksheets("Summary $500-$10K").Range("B8:F21").Copy" as you suggested but is not working. when I try using it I get a Subscript out of range. the other challenge will be when I open a new workbook and try copying the same range to a different range (which will be added to the data already copied from prior day).

    thank you again for your help.

  4. #4
    Registered User
    Join Date
    04-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Need help with copy and paste VBA code

    I modified my previous code to try to make it easier when copying data into a table format, so that when I copy the data to the last row used. I got the following code partially working although it needs to be modified. So that I can copy the same range "B8:B21" from an Active Workbook to my destination Workbook.

    Please Login or Register  to view this content.
    Thanks again for your help.

    THANKS AG

  5. #5
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Need help with copy and paste VBA code

    ThisWorkbook = the workbook in which has the code under it (which i assumed has the code baked into the file but now i noticed it is xlsx so this cant be)

    Try ActiveWorkbook instead of thisworkbook
    "active" means the workbook which has focus at the time of running the code

    are you overwriting the data in consolidated template or are you adding to the bottom?

  6. #6
    Registered User
    Join Date
    04-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Need help with copy and paste VBA code

    i made some changes and is working however I don't know why the first number is coming over as a date. see code below:

    Please Login or Register  to view this content.
    Sub Valuepaste()
    Dim loLastRow As Long

    'Workbooks("04.18.17 SHELBY.xlsx").Worksheets("Summary $500-$10K").Range("B8:F21").Copy
    ActiveWorkbook.Worksheets("Summary $500-$10K").Range("B8:F21").Copy
    With Workbooks("Consolidated_template_new1_WA.xlsx").Worksheets("test")
    loLastRow = .Cells(Rows.Count, 3).End(xlUp).Row + 1
    .Range("C" & loLastRow).PasteSpecial Paste:=xlPasteValues
    End With

    'Workbooks("Consolidated_template_new1_WA.xlsx").Worksheets("test").Range("C4").PasteSpecial Paste:=xlPasteValues

    End Sub
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Need help with copy and paste VBA code

    for some reason the format was lost when i was clearing up the data to enter the data for new week. once i formatted the cells as number , data is coming over correctly. Thank you again for all your help.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Need help with copy and paste VBA code

    Please Login or Register  to view this content.
    this will only paste values and not formats
    if you want formatting as well
    you can try
    Please Login or Register  to view this content.

+ 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. [SOLVED] VB Code to copy paste
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-22-2016, 10:30 AM
  2. [SOLVED] Tweak Code for Copy and Paste Special vs Cut and Paste
    By Adam Schaefer in forum Excel General
    Replies: 1
    Last Post: 04-18-2016, 11:12 AM
  3. [SOLVED] Paste restriction code in vba not affecting GUI copy/paste only Ctrl+V
    By DT211569x in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2016, 01:28 PM
  4. vba copy/paste code don't copy the new values...
    By zois in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2015, 01:44 PM
  5. Replies: 0
    Last Post: 10-29-2013, 09:38 AM
  6. Copy and paste code pasting won't paste just values
    By thehotbreadguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2013, 11:12 PM
  7. Copy/paste code
    By Bob@Sun in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-22-2009, 04:31 PM

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