Aretradeser
Board Regular
- Joined
- Jan 16, 2013
- Messages
- 173
- Office Version
- 2013
- Platform
- Windows
I use this code (CODE 1) to copy data from one Excel sheet to another; but it is very slow. How can I speed it up?
In the sheet where I paste the data (Sheet7), I have this other code (CODE 2), which I think is responsible for the slowness of CODE 1.
CODE 1
CODE 2
In the sheet where I paste the data (Sheet7), I have this other code (CODE 2), which I think is responsible for the slowness of CODE 1.
CODE 1
CSS:
Sub CopyPaste()
Application.ScreenUpdating = False
Sheets("Hoja6").Select
Range("A2:I4678").Select
Selection.Copy
Sheets("Hoja7").Select
Range("B2").Select
ActiveSheet.Paste
Application.ScreenUpdating = True
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ultimaFila, filaID, ultimoCodigo As Integer
ultimaFila = Sheets("Hoja7").Range("B" & Rows.Count).End(xlUp).Row
filaID = Sheets("Hoja7").Range("A" & Rows.Count).End(xlUp).Row
If (ultimaFila > filaID) Then
If (filaID = 1) Then
ultimoCodigo = 1
Else
ultimoCodigo = Sheets("Hoja7").Range("A" & filaID).Value + 1
End If
Sheets("Hoja7").Range("A" & filaID + 1).Value = ultimoCodigo
End If
End Sub