Hello,
My objective: Delete specific range based on duplicates in a specific column , and shift cells up.
I have a large spreadsheet with evenly separated data. I have an example attached of the outcome I want, but I would like to have it in a loop, where the script counts the columns and re-runs.
I am also wondering, can any one of these be referenced to eachother -> for example can TonyRange = ("E2:G") be referenced using a Cells function... or can I vice versa. I have multiple situations in other code where for example I need to identify ("E1:E10") as a range, but I want to do so using the Cells function
I suspect there is a much easier way to do this, but I am very new with VBA and this is what I could come up with. This is only for 2 individuals, I have about 30
I have also attached images of before and after.
Code:
Sub RemoveDuplicates ()
Dim TonyRangeColumn As Integer
Dim NickRangeColumn As Integer
Dim TonyRange As Variant
Dim NickRange As Variant
TonyRangeColumn = 4
NickRangeColumn = 12
TonyRange = ("E2:G")
NickRange = ("M2:O")
ws.Range(TonyRange & (Cells(Rows.Count, TonyRangeColumn).End(xlUp).Row)).RemoveDuplicates Columns:=1
ws.Range(NickRange & (Cells(Rows.Count, NickRangeColumn ).End(xlUp).Row)).RemoveDuplicates Columns:=1
End Sub
My objective: Delete specific range based on duplicates in a specific column , and shift cells up.
I have a large spreadsheet with evenly separated data. I have an example attached of the outcome I want, but I would like to have it in a loop, where the script counts the columns and re-runs.
I am also wondering, can any one of these be referenced to eachother -> for example can TonyRange = ("E2:G") be referenced using a Cells function... or can I vice versa. I have multiple situations in other code where for example I need to identify ("E1:E10") as a range, but I want to do so using the Cells function
I suspect there is a much easier way to do this, but I am very new with VBA and this is what I could come up with. This is only for 2 individuals, I have about 30
I have also attached images of before and after.
Code:
Sub RemoveDuplicates ()
Dim TonyRangeColumn As Integer
Dim NickRangeColumn As Integer
Dim TonyRange As Variant
Dim NickRange As Variant
TonyRangeColumn = 4
NickRangeColumn = 12
TonyRange = ("E2:G")
NickRange = ("M2:O")
ws.Range(TonyRange & (Cells(Rows.Count, TonyRangeColumn).End(xlUp).Row)).RemoveDuplicates Columns:=1
ws.Range(NickRange & (Cells(Rows.Count, NickRangeColumn ).End(xlUp).Row)).RemoveDuplicates Columns:=1
End Sub