+ Reply to Thread
Results 1 to 25 of 25

VBA Copy insert into another workbook _ excel 2013

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: VBA Copy insert into another workbook _ excel 2013

    Hi

    Couple of lines that may help you below, one finds & selects used range minus row 1 (I assumed by your question that you had headers ?) & the other selects row after last used row of active worksheet.

    'Select used range minus headers/row 1
    With ActiveSheet.UsedRange
     .Offset(1, 0).Resize(.Rows.Count - 1).Select 'Selects used range in active worksheet minus row 1 using "offset"
     Selection.Copy ' Copies selected range
    End With

    'Select next empty row
    Dim LastRow As String
    LastRow = ActiveSheet.UsedRange.Rows.Count 'Finds last row of active worksheet
    Rows(LastRow + 1).Select 'Selects next emtpy (non used) row
    Regards
    Steve

  2. #2
    Registered User
    Join Date
    06-14-2012
    Location
    London
    MS-Off Ver
    Excel 2021 LTSC pro plus 2021
    Posts
    52

    Re: VBA Copy insert into another workbook _ excel 2013

    Hi Steve,

    Thanks for those steps they do help - but after selecting the used range how do insert those rows in the "data" workbook is there some code you could post for that please ?

    Regards

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Copy insert into another workbook _ excel 2013

    After your copy command if Data is already open
    
    .copy Workbooks("Data").Sheets("Sheet1").Range("A" & rows.count).End(3)(2)

  4. #4
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: VBA Copy insert into another workbook _ excel 2013

    Using John's code line from above reply this may work for you if you change file path for "Data" workbook and worksheet name

    With ActiveSheet.UsedRange
     .Offset(1, 0).Resize(.Rows.Count - 1).Select 'Selects used range in active worksheet minus row 1 using "offset"
     Selection.Copy ' Copies selected range
     Application.Workbooks.Open ("C:\Users\hartwes1\Desktop\Data.xlsx") 'Open workbook
     .Copy Workbooks("Data").Sheets("Sheet1").Range("A" & Rows.Count).End(3)(2)
    End With

  5. #5
    Registered User
    Join Date
    06-14-2012
    Location
    London
    MS-Off Ver
    Excel 2021 LTSC pro plus 2021
    Posts
    52

    Re: VBA Copy insert into another workbook _ excel 2013

    Hi John

    If I rename the sheet name everytime i use the macrowith yesterdays date isnt that going to be a problem in that coding ?

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Copy insert into another workbook _ excel 2013

    Quote Originally Posted by silverxx12 View Post
    Hi John

    If I rename the sheet name everytime i use the macrowith yesterdays date isnt that going to be a problem in that coding ?
    Yes as it stands now, but it can be modified depending on how you enter the date

    Sub silverxxx12()
    Dim x As String
    x = Format(DateAdd("d", -1, Date), "yyyymmdd")
    Workbooks("Data").Sheets(x).Range("A" & Rows.Count).End(3)(2).Select
    End Sub

  7. #7
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: VBA Copy insert into another workbook _ excel 2013

    John,

    If you dont mind, is the code I enetred ok? it seems to work but wouldnt want to lead someone down the garden path so to speak!

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Copy insert into another workbook _ excel 2013

    Quote Originally Posted by Steve@TRW View Post
    John,

    If you dont mind, is the code I enetred ok? it seems to work but wouldnt want to lead someone down the garden path so to speak!
    Steve, your code seems fine too me. It should work just as well.

  9. #9
    Registered User
    Join Date
    06-14-2012
    Location
    London
    MS-Off Ver
    Excel 2021 LTSC pro plus 2021
    Posts
    52

    Re: VBA Copy insert into another workbook _ excel 2013

    Ok

    I am using part of both of your codes as below:

     With ActiveSheet.UsedRange
        .Offset(1, 0).Resize(.Rows.Count - 1).Select 'Selects used range in active worksheet minus row 1 using "offset"
        Selection.Copy ' Copies selected range
        Application.Workbooks.Open ("C:\Users\silver\Desktop\data.xls")
        
        'remove autofilter'
       
        If ActiveSheet.AutoFilterMode = True Then
        ActiveSheet.AutoFilterMode = False
        End If
        
        .Copy Workbooks("data").Sheets(ActiveSheet.Name).Range("A" & Rows.Count).End(3)(2) '<--------ActiveSheet.Name on this line
    The problems i am faced with are as follows :

    the header row from the temporary data sheet seems to be copied as well - how do i get rid of that i only wish to copy from rows 2 down?

    Also i want to insert the copied cells not paste them after the last row of data as the workbook has formulas at the bottom -

    Thanks really appreciate the help

    so i really i need to copy the data open the workbook

  10. #10
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: VBA Copy insert into another workbook _ excel 2013

    can you attach a copy of temp workbook?

  11. #11
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: VBA Copy insert into another workbook _ excel 2013

    to clarify which row are your headers on ?

  12. #12
    Registered User
    Join Date
    06-14-2012
    Location
    London
    MS-Off Ver
    Excel 2021 LTSC pro plus 2021
    Posts
    52

    Re: VBA Copy insert into another workbook _ excel 2013

    Hi

    The temp book looks like this starting from a1 (row 1 is headers)

    Date time amount value
    1 3 4 5
    2 2 50 78

    The data i want copied begins in row 2 going across the worksheet and down to the last row of data in it

    Hope that clarifies it

    each number is supposed to be under each heading
    Last edited by silverxx12; 01-09-2014 at 09:34 AM.

+ 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. Userform in Excel 2013 disappears while switching an active workbook behind
    By blackarrow in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-17-2013, 09:08 AM
  2. [SOLVED] Create new workbook, then REFERENCE it, Excel 2013
    By rbrian in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2013, 09:09 AM
  3. How to insert a drop down calander in MS Excel 2013
    By shukla_raj23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2013, 12:10 PM
  4. Excel 2013 Automatically insert a row when the last formatted row is used
    By lisakay in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-21-2013, 02:46 PM
  5. Replies: 3
    Last Post: 03-29-2013, 12:35 PM

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