Results 1 to 41 of 41

Excel vba copy data from general sheets and organize them in separate sheets.

Threaded View

excelsubb Excel vba copy data from... 01-20-2013, 12:56 PM
arlu1201 Re: Excel vba copy data from... 01-20-2013, 01:19 PM
excelsubb Re: Excel vba copy data from... 01-20-2013, 01:23 PM
arlu1201 Re: Excel vba copy data from... 01-20-2013, 01:30 PM
excelsubb Re: Excel vba copy data from... 01-20-2013, 01:32 PM
arlu1201 Re: Excel vba copy data from... 01-20-2013, 01:36 PM
excelsubb Re: Excel vba copy data from... 01-20-2013, 01:43 PM
arlu1201 Re: Excel vba copy data from... 01-20-2013, 01:44 PM
excelsubb Re: Excel vba copy data from... 01-20-2013, 01:47 PM
arlu1201 Re: Excel vba copy data from... 01-20-2013, 01:48 PM
excelsubb Re: Excel vba copy data from... 01-20-2013, 02:47 PM
excelsubb Re: Excel vba copy data from... 01-20-2013, 01:51 PM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 06:20 AM
excelsubb Re: Excel vba copy data from... 01-21-2013, 07:39 AM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 08:11 AM
excelsubb Re: Excel vba copy data from... 01-21-2013, 08:36 AM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 08:47 AM
excelsubb Re: Excel vba copy data from... 01-21-2013, 08:53 AM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 09:35 AM
excelsubb Re: Excel vba copy data from... 01-21-2013, 09:44 AM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 09:48 AM
excelsubb Re: Excel vba copy data from... 01-21-2013, 09:59 AM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 10:29 AM
excelsubb Re: Excel vba copy data from... 01-21-2013, 01:26 PM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 01:44 PM
excelsubb Re: Excel vba copy data from... 01-21-2013, 01:54 PM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 01:59 PM
excelsubb Re: Excel vba copy data from... 01-21-2013, 02:08 PM
excelsubb Re: Excel vba copy data from... 01-21-2013, 02:12 PM
arlu1201 Re: Excel vba copy data from... 01-21-2013, 02:14 PM
excelsubb Re: Excel vba copy data from... 01-21-2013, 05:47 PM
arlu1201 Re: Excel vba copy data from... 01-22-2013, 05:29 AM
excelsubb Re: Excel vba copy data from... 01-22-2013, 07:32 AM
arlu1201 Re: Excel vba copy data from... 01-22-2013, 08:44 AM
excelsubb Re: Excel vba copy data from... 01-22-2013, 09:08 AM
arlu1201 Re: Excel vba copy data from... 01-22-2013, 09:20 AM
excelsubb Re: Excel vba copy data from... 01-23-2013, 12:36 AM
excelsubb Re: Excel vba copy data from... 01-23-2013, 12:35 AM
arlu1201 Re: Excel vba copy data from... 01-23-2013, 05:10 AM
excelsubb Re: Excel vba copy data from... 01-24-2013, 07:55 AM
arlu1201 Re: Excel vba copy data from... 01-24-2013, 08:01 AM
  1. #33
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Excel vba copy data from general sheets and organize them in separate sheets.

    Updated code
    Option Explicit
    
    Sub update_sheets()
    Dim ws As Variant
    Dim lrow As Long, i As Long, lastrow As Long
    Dim sname As String
    
    Application.ScreenUpdating = False
    
    For i = 1 To Worksheets.Count
        With Worksheets(i)
            If .Name <> "Ingreso" And .Name <> "Egreso" And .Name <> "Tinterna" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 4 Then .Range("A5:G" & lrow).ClearContents
            End If
        End With
    Next i
    
    With Worksheets("Ingreso")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = 5 To lrow
            sname = .Range("C" & i).Value
            lastrow = Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Row
            .Range("A" & i & ":B" & i).Copy Worksheets(sname).Range("A" & lastrow + 1)
            .Range("D" & i).Copy Worksheets(sname).Range("D" & lastrow + 1)
        Next i
        lastrow = Worksheets("Balance").Range("A" & Rows.Count).End(xlUp).Row
        .Range("A5:B" & lrow).Copy Worksheets("Balance").Range("A" & lastrow + 1)
        .Range("D5:D" & lrow).Copy Worksheets("Balance").Range("D" & lastrow + 1)
    End With
    
    With Worksheets("Egreso")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = 5 To lrow
            sname = .Range("F" & i).Value
            lastrow = Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Row
            .Range("A" & i & ":C" & i).Copy Worksheets(sname).Range("A" & lastrow + 1)
            .Range("E" & i).Copy Worksheets(sname).Range("E" & lastrow + 1)
        Next i
        lastrow = Worksheets("Balance").Range("A" & Rows.Count).End(xlUp).Row
        .Range("A5:C" & lrow).Copy Worksheets("Balance").Range("A" & lastrow + 1)
        .Range("E5:E" & lrow).Copy Worksheets("Balance").Range("E" & lastrow + 1)
    End With
    
    With Worksheets("Tinterna")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = 5 To lrow
            sname = .Range("C" & i).Value
            lastrow = Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Row
            .Range("A" & i & ":B" & i).Copy Worksheets(sname).Range("A" & lastrow + 1)
            .Range("E" & i).Copy Worksheets(sname).Range("C" & lastrow + 1)
            .Range("F" & i).Copy Worksheets(sname).Range("E" & lastrow + 1)
            sname = .Range("D" & i).Value
            lastrow = Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Row
            .Range("A" & i & ":B" & i).Copy Worksheets(sname).Range("A" & lastrow + 1)
            .Range("E" & i).Copy Worksheets(sname).Range("C" & lastrow + 1)
            .Range("F" & i).Copy Worksheets(sname).Range("D" & lastrow + 1)
        Next i
    End With
    
    For i = 1 To Worksheets.Count
        With Worksheets(i)
            If .Name <> "Ingreso" And .Name <> "Egreso" And .Name <> "Tinterna" Then
                .Sort.SortFields.Clear
                .Sort.SortFields.Add Key:=Range("A:A") _
                    , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
                With .Sort
                    .SetRange Range("A:G")
                    .Header = xlYes
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .SortMethod = xlPinYin
                    .Apply
                End With
            End If
        End With
    Next i
    
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by arlu1201; 01-22-2013 at 09:20 AM.

Thread Information

Users Browsing this Thread

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

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