Re: Automate a recorded Macro to shorter Code to hadle variable Ranges
Hello cytop,
Thank you for your response,
Quote
Some users cannot, or will not, download attachments.
Sorry, I was not aware of that, in this Forum.
I would appreciate some help as how to automate the below recorded Macro in such a way that it goes through each row, remove duplicates, and then continue to the last row within the range, which may vary from time to time.:-(
Sub Macro1()
Application.ScreenUpdating = False
Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet2").Select
Range("D2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
ActiveSheet.Range("$D$2:$D$20").RemoveDuplicates Columns:=1, Header:=xlNo
Selection.Copy
Sheets("Sheet1").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Sheet2.Columns("D").Clear
Range("B3").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet2").Select
Range("D2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
ActiveSheet.Range("$D$2:$D$20").RemoveDuplicates Columns:=1, Header:=xlNo
Selection.Copy
Sheets("Sheet1").Select
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Sheet2.Columns("D").Clear
Range("B4").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet2").Select
Range("D2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
ActiveSheet.Range("$D$2:$D$20").RemoveDuplicates Columns:=1, Header:=xlNo
Selection.Copy
Sheets("Sheet1").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Sheet2.Columns("D").Clear
Application.ScreenUpdating = True
End Sub
Display More
Once again, Thank you.:)