+ Reply to Thread
Results 1 to 12 of 12

copy sheet by reference number

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-22-2007
    Posts
    119

    copy sheet by reference number

    Hi, my excel file have 5 sheets (may be more than 4) ,sheet 1,2,3,4... and the sheet name (all serch data) .
    in sheet 1 ,sheet 2, sheet3,sheet4..... incell a3 is the number for reference . in sheet (all sech data ). i create the macro button and the range (n) of this sheet ,when i key the reference number to the sheet1-sheet4 .
    if ,it is the same number to the sheet 1-sheet 4. it will copy the data of that sheets paste to the sheet (all sech data ). if it found the same reference number.
    i attach with the file to see ,how can i do for macro copy code??
    thank
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845
    HI,

    See if this is close to what you want.
    Attached Files Attached Files
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  3. #3
    Forum Contributor
    Join Date
    09-22-2007
    Posts
    119
    hi,thank charles for your best idea code.
    but let me some more 2 questions.
    1.if i want copy to sheet all serch data.. start at row 2 ,how can i modify the code?
    2.if my work book have more than that sheets name .say sheet menu ,sheet other ,sheet tel ,sheet abc .in which i do not copy data from that sheets.
    i do only copy the some column data from sheet 1,2,3,4.... only from the column b,c,d,f g only to the sheet all serch data start at row 5 by the reference number .
    as the eg. how can i modify your code.
    thank
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845
    Hi,

    First off the code does start copying to the "serch data" sheet starting at row 2. However if there is info somewhere else in column "A" then the code will copy to the cell below that info. So you must make sure column "A" is clear except for where the data is to be placed.

    Next the code loops thru all work sheets and if it sees the values you entered on the "serch" sheet it will copy the info that I set for the copy and paste.

    Now the code can be modified to copy the range you want to row5 of the serch sheet, but it would be easier if the info to be copied were formated to be in the columns that need to be copied. IE: c,d,e,f.

  5. #5
    Forum Contributor
    Join Date
    09-22-2007
    Posts
    119
    Hi,charles
    1.sorry ,for my wrong first question. i want to begin at row 5. so i edit your code at lrow = Sheets("all serch data").Range("A65536").End(xlUp).Row + 4 that'is ok but have the blank row .for eg.row33-35 ,that i do not need it.
    2.the second question ,my workbook have more than sheet 1,2,3,4... but it have another sheets name which i do not copy . i want to copy it from sheet1,2,3,4... to the "serch sheet". begin at row 5 .and copy only some column as the example.
    let me show you the eg. i do not understand how to edit the code for using with the first and second of my question.
    i hope you or any one help me this . by give me the eg.to see
    appreciate thank.
    Last edited by pichai; 03-10-2008 at 09:04 AM.

  6. #6
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845
    Hi,

    The following code should eliminate the blank rows.
    I or someone will get back to you with the copy range.

    Sub XferData()
    Application.ScreenUpdating = False
    Dim lrow As Long, lc As Long, lr As Long
    Dim myval As String
    Dim i As Integer
    Dim ws As Worksheet
    For i = 1 To Sheets("all  serch data").Cells(Rows.Count, 14).End(xlUp)
        myval = Cells(i, 14).Text
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> "all  serch data" Then
                If ws.Range("A1").Text = myval Then
                    lrow = Sheets("all  serch data").Range("A65536").End(xlUp).Row + 4
                    If lrow > 4 Then
                        lrow = Sheets("all  serch data").Range("A65536").End(xlUp).Row + 1
                    End If
                    Sheets(ws.Name).Activate
                    lr = Sheets(ws.Name).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row
                    lc = Sheets(ws.Name).Range("IV3").End(xlToLeft).Offset(0, 1).Column
                    Sheets(ws.Name).Range(Cells(3, 1), Cells(lr, lc)).Copy Destination:=Sheets("all  serch data").Range("A" & lrow)
                    Sheets("all  serch data").Activate
                    Exit For
                End If
            End If
        Next ws
    Next i
    Application.ScreenUpdating = True
    End Sub

+ 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