how to copy all the cells of a column and paste it in a row without duplicates in VBA

John Smith

I want to copy an entire column with differents values : string and integer. Then I want to paste the cells in a row, without duplicates for example as you can see, I have a row without duplicates. column

Column become row without duplicates

For the time being , I wrote this code , but it's take so much time , because I have to compare every cell of my row, in order to paste without duplicates. Do you know a function that copy an entire column and past it in a row without duplicates ? THanks

 Sub macro_finale()

Set codes_banques = Range("M35 :M57") ' je mets toute la colonne des codes banques dans la variable codes_banques
Dim code_courant As Integer ' cette variable va prendre chaque code un à un
Dim i As Integer
Dim compteur As Integer
Dim ligne_des_codes  As Integer ' TRES IMPORTANT = déclarer en tant qu'integer _
sinon quand on va comparer les cellules il comperera mal
Dim flag As Integer ' indicateur pour informer
flag = 0
compteur = 4


For Each cell In codes_banques

   '  MsgBox "voici le contenue de la colonne libellée " + cell.Value ' ligne test supprimable
    flag = 0 ' à la base le code banque n'est pas repertoriée
    If cell.Value <> "Code" Then ' IMPORTANT : si la cellule contient le mot code _
    on ne fait rien , on compare rien car c'est pas une code banque
    ' Remarque : c'est sensible à la casse, donc ne pas mettre code avec c miniscule
        code_courant = cell.Value



        For i = 4 To 6
            If Not Sheets("coller_ici").Cells(1, i).Value = Null Then
            ligne_des_codes = Sheets("coller_ici").Cells(1, i).Value
             End If
            MsgBox " voici code courant" & code_courant
             MsgBox " voici ligne des codes " & ligne_des_codes

             If code_courant = ligne_des_codes Then

                flag = 1 ' donc le code banque est déjà repértorié dans la feuille coller_ici _
                on ne va donc pas le rajouter dans la feuille coller_ici

            End If
        Next

       If flag = 0 Then ' donc le code banque n'est pas encore repértorié dans coller ici( dans la 1ere ligne )
       'on va donc l'ajouter
            Sheets("coller_ici").Cells(1, compteur).Value = code_courant
            compteur = compteur + 1
        End If
     End If
Next cell



End Sub
DisplayName

you could try

Dim cell As Range
With CreateObject("Scripting.Dictionary")
    For Each cell In Range("M20:M1000").SpecialCells(xlCellTypeConstants)
        .Item(cell.Value) = 1
    Next
    Sheets("coller_ici").Cells(1, 4).Resize(, UBound(.Items) + 1).Value = .Keys
End With

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to copy paste all formats AND values without using select in vba

Find match within a column in a different worksheet, then copy paste specific cells to matched row in VBA

How to copy paste columns adjust height of cells with images without distorting the images. (Excel VBA)

VBA: Copy and paste cells in a email without losing formatting

excel vba copy paste cells without user noticing

Excel VBA Copy & Paste a Range of Cells Repeatedly in a Column

VBA - Copy Cells from Column A and B and Paste in New Sheet

Copy and paste active column without changing cells formats

Loop through all cells in a column and copy and paste text if match is found

VBA - How to copy a column once but paste it twice?

VBA code to copy cells in specific column and paste (value) it to cells in specific column on another Sheet based on conditions

How to copy/paste formula in filtered/visible cells via VBA in Excel

VBA - How to copy data from a single cell and paste into merged cells

Copy and Paste row under specific column Heading VBA

How do I copy and paste cells without cell formula with Powershell?

Excel VBA Copy and Paste (without using Copy+Paste functions) on empty row

Copy all figures in a column and paste it to row with ID value 1 smaller

Excel VBA Copy block of cells with variable row and column number

Copy and paste values without duplicates in spredsheets

VBA: Copy cells, paste as a picture, then save as a picture?

Copy and Paste a Range of Cells using VBA

Excel vba macro to copy cells and paste in another

How to copy from a cell and paste in a new row of a different table VBA

VBA excel: How do I get data in cells as an array up one row in the same column without selecting?

Copy/Paste a formula in Libreoffice without adjusting the cells

VBA Paste Column starting at row

How copy vba cells

How to copy last row of data in all worksheets and paste it into one worksheet

VBA - How to Copy and Paste the last value in a column to another Sheet