Guinaba
Board Regular
- Joined
- Sep 19, 2018
- Messages
- 233
- Office Version
- 2016
- Platform
- Windows
Hey guys,
I am using the code below to copy the data from a range and paste into a table. I am deleting the data in the table everytime beforing copying the new range. Just wondering if there is a way to make this code run faster?
I am using the code below to copy the data from a range and paste into a table. I am deleting the data in the table everytime beforing copying the new range. Just wondering if there is a way to make this code run faster?
VBA Code:
Sub CopyFromRange ()
Dim wrksht As Worksheet
Dim objListObj As ListObject
Set wrksht = ActiveWorkbook.Worksheets("IBPData1")
Set objListObj = wrksht.ListObjects("tFcst_1")
With Sheets("IBPData1")
'Find the last non-blank cell in column A(1)
LRow = .Cells(Rows.Count, 2).End(xlUp).Row
'Clean Table content
With objListObj.DataBodyRange
If .Rows.Count > 1 Then .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Rows.Delete
On Error Resume Next
.Rows(1).SpecialCells(xlCellTypeConstants).ClearContents
End With
'Copy Source Range
.Range(Cells(3, 2), Cells(LRow, 6)).Copy
.Range("H3:L" & LRow).PasteSpecial xlPasteValues
'Remove the animation around the copied cell
Application.CutCopyMode = False
objListObj.Resize Range("H2:L" & LRow)
End With
End Sub