+ Reply to Thread
Results 1 to 14 of 14

copy range in worksheets paste to master

  1. #1
    Registered User
    Join Date
    01-31-2010
    Location
    Washington
    MS-Off Ver
    Excel 2007
    Posts
    5

    copy range in worksheets paste to master

    I am working with a workbook that i have created. The workbook has around thirty worksheets all with the starting nave of "DIV". I have a code that will loop throught the wrok book and copy the used range and insert them into a master. However what i need is a code that will loop through the wroksheets and only copy the used range only in columns A:P and starting in row 10 (i have headers from row 1-10). I have columns beyond "P" that has working information for that worksheet and do not want to copy it over to the master.

    Thank you for the help..

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: copy range in worksheets paste to master

    Hi,

    Use something like

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-31-2010
    Location
    Washington
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: copy range in worksheets paste to master

    The code you gave me only seems to copy one row. I believe it could be because there is blank rows in the range. Is there a way for it to go all the way to the bottom and then com back up to the first cell with value. I cannot get rid of the blank rows, they must remain.

    Thank you

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: copy range in worksheets paste to master

    Hi,

    Yes, just substitute

    Please Login or Register  to view this content.
    Rgds

  5. #5
    Registered User
    Join Date
    01-31-2010
    Location
    Washington
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: copy range in worksheets paste to master

    I am getting a run time error on that code line

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: copy range in worksheets paste to master

    Hi,

    Have you substituted it for the original line
    Please Login or Register  to view this content.
    and left all the other code in place?

    Rgds

  7. #7
    Registered User
    Join Date
    01-31-2010
    Location
    Washington
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: copy range in worksheets paste to master

    I did change it out. here is the code i am working with
    Private Sub CommandButton1_Click()

    Dim DESTSH As Worksheet
    Dim Last As Long
    Dim lUsedRows As Long, x As Long

    With Application
    .ScreenUpdating = False
    .EnableEvents = False
    End With

    ' delete existing rows in estimate sheet
    Application.DisplayAlerts = False
    On Error Resume Next
    ActiveWorkbook.Worksheets("ESUM").Select
    Rows("13:10000").Select
    Selection.DELETE Shift:=x1up
    On Error GoTo 0
    Application.DisplayAlerts = True

    Set DESTSH = ActiveWorkbook.Worksheets("ESUM")


    For x = 1 To Sheets.Count
    If Left(Sheets(x).Name, 3) = "DIV" Then
    lUsedRows = Range(Sheets(x).Range("A10"), Sheets(x).Range("A" & Rows.Count).End(xlUp)).Rows.Count
    Last = LASTROW(DESTSH)
    Sheets(x).Range("A10:P" & lUsedRows).Copy Destination:=DESTSH.Cells(Last + 1, 1)
    End If
    Next x
    ExitTheSub:
    Application.Goto DESTSH.Cells(1)
    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With
    End Sub

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range in worksheets paste to master

    Maybe this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  9. #9
    Registered User
    Join Date
    01-31-2010
    Location
    Washington
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: copy range in worksheets paste to master

    it made no difference.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range in worksheets paste to master

    Or:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: copy range in worksheets paste to master

    HI
    try these codes
    Please Login or Register  to view this content.
    ravi

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range in worksheets paste to master

    Ravi, resist the urge to hardcode a bottom row number like that. Each version of Excel has a different "bottom row" and hardcoding 65536 can have bad results on Excel 2007+ users.

    Use the Rows.Count syntax in place of the hardcoded number so Excel always starts from the actual bottom of the sheet, regardless of version.

  13. #13
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: copy range in worksheets paste to master

    Hi
    Thanks JB for your suggestion. I will do so hereafter.
    Ravi

  14. #14
    Registered User
    Join Date
    09-05-2010
    Location
    abu Dhabi
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: copy range in worksheets paste to master

    Hi,

    I have searched and searched in almost all the forums, but i have not been able to achieve what i need. I have to create a work sheet for my manager where he will assign different task/projects to us, and the same would be a updated in a shared file kept in our common DIR thus whenever we open we can view our individual sheets view the task assigned and update accordingly.

    Now, i have already created a Master sheet where task assigned gets populated on individual sheet but i am stuck at is how get the master sheet updated for column (Status) & column(update) when we update our sheets in column (F) & column (G) the same needs to be updated on master sheet ?

    Formula/macro anything is it possible?

    please
    Attached Files Attached Files

+ 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