chipsworld
Board Regular
- Joined
- May 23, 2019
- Messages
- 169
- Office Version
- 365
HI all,
Need a hand please...
I am puzzled as to why the below code takes my file from 3.5mb to 100mb after running it once.
I thought it was empty rows being added, but with the code to delete empty rows, it is still happening.
Where did I go wrong...
All I am doing is copying data to my active workbook from another version of the same workbook, then eliminate dups. Not sure how adding 3 to 10 rows of data could increase the file size so much...
Thanks in advance for any help!
Need a hand please...
I am puzzled as to why the below code takes my file from 3.5mb to 100mb after running it once.
I thought it was empty rows being added, but with the code to delete empty rows, it is still happening.
Where did I go wrong...
All I am doing is copying data to my active workbook from another version of the same workbook, then eliminate dups. Not sure how adding 3 to 10 rows of data could increase the file size so much...
Thanks in advance for any help!
VBA Code:
Public Sub import_new_data()
' Get customer workbook...
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook
Dim targetsheet As Worksheet
Dim sourceSheet As Worksheet
Dim response As String
Dim LastRow As Long
On Error Resume Next
response = MsgBox("Please make sure you select the correct historical file to import" _
& vbCrLf & "Are you sure you want to Proceed?", vbYesNo, "ALERT!!!!")
If response = vbYes Then
Set targetWorkbook = Application.ThisWorkbook
Set targetsheet = targetWorkbook.Sheets("Historical")
' get the customer workbook
filter = "*.xl* (*.xls*),*.xls*"
caption = "Please Select file to import "
customerFilename = Application.GetOpenFilename(filter, , caption)
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
Set sourceSheet = customerWorkbook.Sheets("Historical")
' copy data from customer to target workbook
Dim LRSrc As Long, LRDest As Long, SrcRng As Range
With sourceSheet
LRSrc = .Cells(.Rows.Count, 2).End(xlUp).Row 'assumes column 2 is contiguous
Set SrcRng = .Range("A2:AJ" & LRSrc) 'starts at row 2 to avoid header
End With
With targetsheet
LRDest = .Cells(.Rows.Count, 2).End(xlUp).Row 'assumes column 2 is contiguous
SrcRng.Copy .Cells(LRDest + 1, 1)
End With
Call Module1.Remove_Dups
Else: response = vbNo
MsgBox "Nothing was Imported", vbOKOnly
End If
' Close customer workbook
customerWorkbook.Close (False)
End Sub
Public Sub Remove_Dups()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Historical")
With ws
.UsedRange.RemoveDuplicates Columns:=2, Header:=xlYes
'.Columns("A:AJ").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub