Closed Thread
Results 1 to 3 of 3

Macro to copy row with same num (sheet1) and sum its column in another sheet

  1. #1
    Registered User
    Join Date
    03-12-2014
    Location
    Tonga
    MS-Off Ver
    Excel 2007
    Posts
    10

    Macro to copy row with same num (sheet1) and sum its column in another sheet

    Please help!! i want a macro to search for same num in first collumn and copy all the row with same num to another sheet and total up some of its column.. please download my sample file for better understand what i need..
    I try this code but im stuck..

    Sub maka()
    Dim dic As Object, i As Long, temp As String, e
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = 1
    With Sheets("sheet1").Cells(1).CurrentRegion
    For i = 1 To .Columns.Count
    temp = CStr(.Cells(2, i).Value)
    If Not dic.exists(temp) Then
    Set dic(temp) = .Rows(1)
    End If
    Set dic(temp) = Union(dic(temp), .Rows(i))
    Next
    End With
    For Each e In dic
    If Not IsSheetExists(e) Then
    Sheets.Add(after:=Sheets(Sheets.Count)).Name = e
    With Sheets(e)
    .Cells.Clear
    dic(e).Copy .Cells(1)
    .Columns.AutoFit
    End With
    End If
    Next
    End Sub

    Function IsSheetExists(ByVal txt As String) As Boolean
    On Error Resume Next
    IsSheetExists = Len(Sheets(txt).Name)
    On Error GoTo 0
    End Function

    thank you
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Macro to copy row with same num (sheet1) and sum its column in another sheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    And the this is related to your thread
    http://www.excelforum.com/excel-prog...nding-row.html

    Better continue there.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  3. #3
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Macro to copy row with same num (sheet1) and sum its column in another sheet

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy certain data from Sheet1 to Sheet 2 based on values in a column on Sheet1
    By theglitch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2013, 01:28 PM
  2. [SOLVED] Need a Macro that copy a dynamic list from sheet1 and save it on sheet 2
    By EjazVirk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2013, 08:54 AM
  3. Excel macro to copy data from Sheet1 row into Sheet2 column
    By peleong in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-12-2011, 10:56 AM
  4. Macro to copy information over from sheet1,2,3 to Sheet 4
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-03-2011, 04:16 AM
  5. Replies: 7
    Last Post: 10-21-2005, 07:05 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