Ok. Try this code - instructions are given below the code on how to use it -
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
.Range("A" & i & ":B" & i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Range("D" & i).Copy Worksheets(sname).Range("D" & Rows.Count).End(xlUp).Offset(1, 0)
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
.Range("A" & i & ":C" & i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Range("E" & i).Copy Worksheets(sname).Range("E" & Rows.Count).End(xlUp).Offset(1, 0)
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
.Range("A" & i & ":B" & i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Range("E" & i).Copy Worksheets(sname).Range("C" & Rows.Count).End(xlUp).Offset(1, 0)
.Range("F" & i).Copy Worksheets(sname).Range("E" & Rows.Count).End(xlUp).Offset(1, 0)
sname = .Range("D" & i).Value
.Range("A" & i & ":B" & i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Range("E" & i).Copy Worksheets(sname).Range("C" & Rows.Count).End(xlUp).Offset(1, 0)
.Range("F" & i).Copy Worksheets(sname).Range("D" & Rows.Count).End(xlUp).Offset(1, 0)
Next i
End With
Application.ScreenUpdating = True
End Sub
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
Choose Insert | Module
Where the cursor is flashing, choose Edit | Paste
To run the Excel VBA code:
Choose Tools | Macro | Macros
Select a macro in the list, and click the Run button
Bookmarks