Andrada_Kio
New Member
- Joined
- Oct 24, 2018
- Messages
- 8
Hi,
I have a VBA code to merging worksheets (I need only some columns) , but it works very slowly , 45 min to run the macro.
Can someone tell me if the macro can be changed to work faster. Bellow the code :
Thank you!!
Code:
Thank you!!!
I have a VBA code to merging worksheets (I need only some columns) , but it works very slowly , 45 min to run the macro.
Can someone tell me if the macro can be changed to work faster. Bellow the code :
Thank you!!
Code:
Code:
[COLOR=#333333]Sub ConsolidateTable()[/COLOR]
[COLOR=#333333]For i = 2 To Sheets("DataBase JDE").Range("A1048576").End(xlUp).Row[/COLOR]
[COLOR=#333333]If Not IsEmpty(Sheets("DataBase JDE").Range("A" & i)) Then[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("A" & Sheets("DataBase Total").Range("A1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("A" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("B" & Sheets("DataBase Total").Range("B1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("B" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("C" & Sheets("DataBase Total").Range("C1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("AA" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("D" & Sheets("DataBase Total").Range("D1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("C" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("E" & Sheets("DataBase Total").Range("E1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("E" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("F" & Sheets("DataBase Total").Range("F1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("F" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("G" & Sheets("DataBase Total").Range("G1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("Q" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("H" & Sheets("DataBase Total").Range("H1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("R" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("I" & Sheets("DataBase Total").Range("I1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("S" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("J" & Sheets("DataBase Total").Range("J1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("U" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("K" & Sheets("DataBase Total").Range("K1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("AB" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("L" & Sheets("DataBase Total").Range("L1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("BE" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("M" & Sheets("DataBase Total").Range("M1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("P" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("N" & Sheets("DataBase Total").Range("N1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("BC" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("O" & Sheets("DataBase Total").Range("O1048576").End(xlUp).Row + 1) = Sheets("DataBase JDE").Range("BD" & i)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("P" & Sheets("DataBase Total").Range("P1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]Next i[/COLOR]
[COLOR=#333333]For J = 2 To Sheets("DataBase JDI").Range("A1048576").End(xlUp).Row[/COLOR]
[COLOR=#333333]If Not IsEmpty(Sheets("DataBase JDI").Range("A" & J)) Then[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("A" & Sheets("DataBase Total").Range("A1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("B" & Sheets("DataBase Total").Range("B1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("A" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("C" & Sheets("DataBase Total").Range("C1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("CN" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("D" & Sheets("DataBase Total").Range("D1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("E" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("E" & Sheets("DataBase Total").Range("E1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("G" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("F" & Sheets("DataBase Total").Range("F1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("AP" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("G" & Sheets("DataBase Total").Range("G1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("FP" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("H" & Sheets("DataBase Total").Range("H1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("CO" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("I" & Sheets("DataBase Total").Range("I1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("BB" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("J" & Sheets("DataBase Total").Range("J1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("BC" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("K" & Sheets("DataBase Total").Range("K1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("F" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("L" & Sheets("DataBase Total").Range("L1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("M" & Sheets("DataBase Total").Range("M1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("BD" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("N" & Sheets("DataBase Total").Range("N1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("DF" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("O" & Sheets("DataBase Total").Range("O1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("CL" & J)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("P" & Sheets("DataBase Total").Range("P1048576").End(xlUp).Row + 1) = Sheets("DataBase JDI").Range("AR" & J)[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]Next J[/COLOR]
[COLOR=#333333]For k = 2 To Sheets("DataBase SJ").Range("A1048576").End(xlUp).Row[/COLOR]
[COLOR=#333333]If Not IsEmpty(Sheets("DataBase SJ").Range("A" & k)) Then[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("A" & Sheets("DataBase Total").Range("A1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("A" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("B" & Sheets("DataBase Total").Range("B1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("B" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("C" & Sheets("DataBase Total").Range("C1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("AA" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("D" & Sheets("DataBase Total").Range("D1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("AG" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("E" & Sheets("DataBase Total").Range("E1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("L" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("F" & Sheets("DataBase Total").Range("F1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("G" & Sheets("DataBase Total").Range("G1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("D" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("H" & Sheets("DataBase Total").Range("H1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("I" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("I" & Sheets("DataBase Total").Range("I1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("K" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("J" & Sheets("DataBase Total").Range("J1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("K" & Sheets("DataBase Total").Range("K1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("L" & Sheets("DataBase Total").Range("L1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("M" & Sheets("DataBase Total").Range("M1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("N" & Sheets("DataBase Total").Range("N1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("AG" & k)[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("O" & Sheets("DataBase Total").Range("O1048576").End(xlUp).Row + 1) = " "[/COLOR]
[COLOR=#333333]Sheets("DataBase Total").Range("P" & Sheets("DataBase Total").Range("P1048576").End(xlUp).Row + 1) = Sheets("DataBase SJ").Range("AF" & k)[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]Next k[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
Thank you!!!
Last edited by a moderator: