Dear All
I have created vba to copy rows to Columns. It works but it’s very slow.
As more entries are it would become slower.
Is it possible to make it faster?
Please not in my main macro I use SpeedOn and SpeedOff
Your help would be greatly appreciated.
Kind Regards
Biz
I have created vba to copy rows to Columns. It works but it’s very slow.
As more entries are it would become slower.
Is it possible to make it faster?
Please not in my main macro I use SpeedOn and SpeedOff
Code:
Sub DataTranfer()
Dim rngCopy As Range
Dim rngPaste As Range
Dim rngStart As Range
Dim rngEnd As Range
Dim lr As Long
Dim r, c As Single
Dim rCells As Range
Dim lCol As Long
Dim sCol As String
'Find Last Column on Data Worksheet tab
With wsDestination
lCol = .Cells.Find(What:="*", _
After:=.Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
End With
sCol = ColNumToLetter(lCol)
Set rngStart = searchRng
Set rngEnd = ws.Range("A" & ws.Range("A" & Rows.Count).End(xlUp).Row)
For Each rngCopy In ws.Range(Range(searchRng, rngEnd).Address).SpecialCells(xlCellTypeConstants).Areas
Set rngPaste = wsDestination.Range("A" & Application.Max(2, wsDestination.Range("A" & Rows.Count).End(xlUp).Row + 1))
'Loop thru rngCopy Cells
For Each rCells In rngCopy
'Match Column Header to make sure correct information is pasted
c = Application.Match(rCells, wsDestination.Range("A1:" & sCol & 1), 0)
r = 0
'Copy items from Col B
rngPaste.Offset(r, c - 1) = rCells.Offset(0, 1).Value
Next rCells
Next rngCopy
'Formating
lr = wsDestination.Range("A" & Rows.Count).End(xlUp).Row
With wsDestination
.Range("C2:C" & lr).NumberFormat = "dd/mm/yyyy"
.Range("F2:G" & lr).NumberFormat = "dd/mm/yyyy"
.Range("M2:O" & lr).NumberFormat = "dd/mm/yyyy"
End With
wsDestination.Cells.EntireColumn.AutoFit
'Release memory
Set rngStart = Nothing
Set rngEnd = Nothing
Set rngPaste = Nothing
End Sub
Private Sub SpeedOn()
'Speeding Up VBA Code
With Application
.ScreenUpdating = False 'Prevent screen flickering
'.Calculation = xlCalculationManual 'Preventing calculation
.DisplayAlerts = False 'Turn OFF alerts
.EnableEvents = False 'Prevent All Events
End With
End Sub
Private Sub SpeedOff()
'Speeding Up VBA Code
With Application
.ScreenUpdating = True 'Prevent screen flickering
'.Calculation = xlAutomatic 'Preventing calculation
.DisplayAlerts = True 'Turn OFF alerts
.EnableEvents = True 'Prevent All Events
End With
End Sub
Your help would be greatly appreciated.
Kind Regards
Biz