I want to append names from column g to the end of column A and then remove duplicates

danyu

New Member
Joined
Nov 22, 2022
Messages
10
Office Version
  1. 2013
Platform
  1. Windows
Hi Everyone,

I want to append names from column g to the end of column A and then remove duplicates. I was able to do it this way below, but I feel like this way will be prone to glitching or something. Is there a better way to do this? Also, is there a simple way to have vlookup match with names that have Jr. Sr. etc? I've read that it can be done with vlookup wildcards, but it doesnt seem to work for me. Thanks in advance!

Sheets("Names").Select
Range("G2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=18
Range("A700").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("A:A").Select
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$A$1500").RemoveDuplicates Columns:=1, Header:=xlYes
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
How about this?
VBA Code:
Sub myFunction()
  Dim gRow As Integer, aRow As Integer

  gRow = Cells(Rows.Count, 7).End(xlUp).Row
  aRow = Cells(Rows.Count, 1).End(xlUp).Row

  For i = 2 To gRow
    Cells((aRow + i) - 1, 1).Value =  Cells(i, 7).Value
  Next

  ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
 
Upvote 0
How about this?
VBA Code:
Sub myFunction()
  Dim gRow As Integer, aRow As Integer

  gRow = Cells(Rows.Count, 7).End(xlUp).Row
  aRow = Cells(Rows.Count, 1).End(xlUp).Row

  For i = 2 To gRow
    Cells((aRow + i) - 1, 1).Value =  Cells(i, 7).Value
  Next

  ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
let me try, thanks!
 
Upvote 0
How about this?
VBA Code:
Sub myFunction()
  Dim gRow As Integer, aRow As Integer

  gRow = Cells(Rows.Count, 7).End(xlUp).Row
  aRow = Cells(Rows.Count, 1).End(xlUp).Row

  For i = 2 To gRow
    Cells((aRow + i) - 1, 1).Value =  Cells(i, 7).Value
  Next

  ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
 
Upvote 0
Hi, It works! Thanks!

However, I wanted to run one macro and have this run across multiple sheets (each from a column like g to a), when I try using this code on another sheet I get a duplicate error. Is there a way to use this on multiple sheets?

Sheets("names").Select
Dim gRow As Integer, aRow As Integer

gRow = Cells(Rows.Count, 7).End(xlUp).Row
aRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To gRow
Cells((aRow + i) - 1, 1).Value = Cells(i, 7).Value
Next

ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes

Sheets("name2").Select
Dim gRow As Integer, aRow As Integer

gRow = Cells(Rows.Count, 9).End(xlUp).Row
aRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To gRow
Cells((aRow + i) - 1, 1).Value = Cells(i, 9).Value
Next

ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes


Thanks again!
 
Upvote 0
Hi, It works! Thanks!

However, I wanted to run one macro and have this run across multiple sheets (each from a column like g to a), when I try using this code on another sheet I get a duplicate error. Is there a way to use this on multiple sheets?

Sheets("names").Select
Dim gRow As Integer, aRow As Integer

gRow = Cells(Rows.Count, 7).End(xlUp).Row
aRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To gRow
Cells((aRow + i) - 1, 1).Value = Cells(i, 7).Value
Next

ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes

Sheets("name2").Select
Dim gRow As Integer, aRow As Integer

gRow = Cells(Rows.Count, 9).End(xlUp).Row
aRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To gRow
Cells((aRow + i) - 1, 1).Value = Cells(i, 9).Value
Next

ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes


Thanks again!
Hi, gald the hear it did work! Can you provide some sample worksheet names? Or all worksheets?
 
Upvote 0
Hi, gald the hear it did work! Can you provide some sample worksheet names? Or all worksheets?
Hi, one tab I have is called Blitz, and another is CBS. I can also do all worksheets in between like a first : end tab.

Thanks again, truly appreciated!
 
Upvote 0
For specific worksheets:
VBA Code:
Sub myFunction()
  Dim gRow As Integer, aRow As Integer
  Dim wsheets As Variant
  Dim ws As Variant
 
  wsheets = Array("Blitz", "CBS")

  For Each ws In wsheets
    With ws
      gRow = .Cells(Rows.Count, 7).End(xlUp).Row
      aRow = .Cells(Rows.Count, 1).End(xlUp).Row

      For i = 2 To gRow
         .Cells((aRow + i) - 1, 1).Value =  .Cells(i, 7).Value
      Next

      .Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
    End With
  Next ws
End Sub
To loop through all worksheets:
VBA Code:
Sub myFunction()
  Dim gRow As Integer, aRow As Integer
  Dim ws As Worksheet

  For Each ws In ThisWorkbook.Worksheets
    With ws
      gRow = .Cells(Rows.Count, 7).End(xlUp).Row
      aRow = .Cells(Rows.Count, 1).End(xlUp).Row

      For i = 2 To gRow
         .Cells((aRow + i) - 1, 1).Value =  .Cells(i, 7).Value
      Next

      .Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
    End With
  Next
End Sub
 
Upvote 0
Hi danju,

maybe
VBA Code:
Sub MrE1222800()
Dim lngCount As Long
Dim lngIndex As Long

'will work on all sheets from First to Last
For lngIndex = Worksheets("First").Index To Worksheets("Last").Index
  With Worksheets(lngIndex)
     lngCount = .Cells(.Rows.Count, "G").End(xlUp).Row - 1
    .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(lngCount, 1).Value = Range("G2").Resize(lngCount, 1).Value
    .Columns(1).RemoveDuplicates Columns:=1, Header:=xlYes
  End With
Next lngIndex
End Sub

Ciao,
Holger
 
Upvote 0
For specific worksheets:
VBA Code:
Sub myFunction()
  Dim gRow As Integer, aRow As Integer
  Dim wsheets As Variant
  Dim ws As Variant
 
  wsheets = Array("Blitz", "CBS")

  For Each ws In wsheets
    With ws
      gRow = .Cells(Rows.Count, 7).End(xlUp).Row
      aRow = .Cells(Rows.Count, 1).End(xlUp).Row

      For i = 2 To gRow
         .Cells((aRow + i) - 1, 1).Value =  .Cells(i, 7).Value
      Next

      .Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
    End With
  Next ws
End Sub
To loop through all worksheets:
VBA Code:
Sub myFunction()
  Dim gRow As Integer, aRow As Integer
  Dim ws As Worksheet

  For Each ws In ThisWorkbook.Worksheets
    With ws
      gRow = .Cells(Rows.Count, 7).End(xlUp).Row
      aRow = .Cells(Rows.Count, 1).End(xlUp).Row

      For i = 2 To gRow
         .Cells((aRow + i) - 1, 1).Value =  .Cells(i, 7).Value
      Next

      .Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
    End With
  Next
End Sub
Thanks! what if they aren't always in the same column? Sometimes the data set is in column F, G , I etc, but I want to copy to A. I was going copy the code for each individual sheet.
Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,139
Members
452,546
Latest member
Rafafa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top