Maybe someone could take a look at this code and tell me if I’m on the right path. I am trying to open a file we export data to, do a text to columns on one column, remove duplicates based on two criteria, sort the file, then copy and paste two different regions of the worksheet into my worksheet. Not sure if I got it right as I am working on this on my phone but will try it later on the computer. Any help or guidance is greatly appreciated, thanks.
Code:
[COLOR=#454545][FONT=UICTFontTextStyleBody]
[/FONT][/COLOR]
[COLOR=#454545][FONT=UICTFontTextStyleBody]
[/FONT][/COLOR]
[COLOR=#454545][FONT=UICTFontTextStyleBody]Sub ImportAllData()
' ImportData Macro
[FONT=UICTFontTextStyleBody]
DIM wb AS Workbook: Set wb = Thisworkbook
[/FONT][FONT=UICTFontTextStyleBody]DIM df AS Workbook: Set df = 1.xls[/FONT]
[FONT=UICTFontTextStyleBody]
[/FONT]
[FONT=UICTFontTextStyleBody]DIM ws AS Worksheet: Set ws = wb.sheets(“Today”)[/FONT]
[FONT=UICTFontTextStyleBody]DIM ds AS Worksheet: Set ds = df.Activesheet[/FONT]
[COLOR=#000000]
[/COLOR]
' This section removed duplicates
WaitingMsg.Show
Application.ScreenUpdating = False
Workbooks.Open Filename:="I:\Location\1.xls" Ds.Range("E2:E" & rows.count).Select
Selection.TextToColumns Destination:=Range("E2"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 9), Array(10, 1)), TrailingMinusNumbers:=True
ds.Range("$A$1:$AJ$600").RemoveDuplicates Columns:=Array(2, 3), _
Header:=xlYes
Application.DisplayAlerts = False
' Sort1 Macro
Range("I1").Select
ds.Sort.SortFields.Clear
ds.Sort.SortFields.Add Key:=Range("I1"), SortOn _
:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ds.Sort
.SetRange Range("A2:K600")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
' This section copies the data and pastes into the Workbook
ds.Range("A2:C" & rows.count).Select
Selection.Copy
ws.Range("D3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False ds.Range("F2:K" & rows.count).Select
Application.CutCopyMode = False
Selection.Copy
ws.Range("I3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
df.Activate
Application.CutCopyMode = False
ActiveWindow.Close SaveChanges:=False
Application.DisplayAlerts = False
ws.Range("D3").Select
Unload WaitingMsg
End With
[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleBody] End Sub[/FONT][/COLOR]
Last edited: