Copy or Transpose multiple columns into a single column.

harzer

Board Regular
Joined
Dec 15, 2021
Messages
161
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,
I allow myself to submit my problem since I do not know how to provide a solution to my problem
What I want to do is transpose or copy the following cells:
1. Non-empty cells will be copied, which means that empty cells will not be copied.
2. Visible cells, which means that hidden cells will not be copied.
3. Cells that contain formulas will not be copied either.
4. In line number 1 we have the headers.
We will copy the cells in column "D" from cell "D2" of the following sheets: "Classe A", "Classe B", "Classe C", "Classe D", "Classe E", "Classe F", "Classe AK", "Classe BK", "Classe CK", "Classe A4T", "Classe B4T", "Classe C4T", "Classe AK4T", "Classe BK4T" and "Classe CK4T", 15 sheets in total, to paste them in column "A" one below the other, in the "Liste" sheet from cell "A2".
Column "D" of the source sheets contains first and last names, it may happen that one or more columns in the source sheets do not contain data from cells "D2", please take this detail into account in your programming.
When all the cells in columns "D" of the source sheets are copied into column "A" of the "Liste" sheet, we will remove the duplicates and sort the remaining list in ascending order.
I would like to ask you for a VBA code that uses LBound or UBound so that it is fast.
Unless I am mistaken, I have the desired result in column "A" of the "Liste" sheet
I remain at your disposal if you need any further information.
Thank you for your cooperation.

sheets("Classe A")

MaListe.xlsm
ABCDEFGHIJKLMNOPQ
1BagueCageEleveursStamHrlKnWaHolkFlSchKlkKlKrolImpTNTotal
2CH597Perez Renée124723231718990
3PH12Jean Pierre25422221417883
4124Dupuy Francois36921211516881
5236Guillot Louis44421201415777
63413Hubert Joseph54B20241514780
85687Carpentier Antoine478F23221414780
96758Sanchez CharlesHUN2522211314777
107814Dupuis NicolasKLM2121211313775
118969Moulin EtienneGTR5421201213773
1291025Louis Guillaume1220201212771
13101198Deschamps Michel520201112770
14111232Huet Andre6519201112769
151213478220
161314147Perez RenéeBF450
171415258Boucher PaulineLO540
181516456Fleury AugusteGFD690
191617987Royer JulesHGY250
20171842Klein GeorgesSFR740
21181966Jacquet JulienHYO560
22192055Adam PhilibertJU1240
23202144Paris FernandXWQ780
24212277Perez RenéeMPK580
25222333Marty EdmondVBF980
26232422Aubry ToussaintVCD2540
27242511Guyot JehanQSA110
282526774Carre AnthoineDEZ470
292627325Charles GermainHGT470
302728428Renault ClementBNH110
312829761Charpentier ArmandCDQ850
322930455Menard ConstantPOI470
33303198Maillard FranciscusVFD690
343132111Aubry ToussaintNNN470
353233287Bertin ArthurNBV470
363334473MP47O0
373435128Herve OlivierXXW540
383536411Schneider DanielPOI730
393637577Fernandez MarinBBB740
403738665Le Gall BaptisteMPO410
413839998Collet MariusKNN030
423940225Leger ElieBHG740
434041177Bouvier IsidoreJUY580
444142669Maillard FranciscusPOW820
454243331Guyot JehanJUY650
464344124Bertin ArthurPOP110
Classe A
Cell Formulas
RangeFormula
D2D2=D16
D44,D46D44=D33
D45D45=D27
Q8:Q46,Q2:Q6Q2=SUM(F2:P2)


Sheets("Classe B")

MaListe.xlsm
ABCDEFGHIJKLMNOPQ
1BagueCageEleveursStamHrlKnWaHolkFlSchKlkKlKrolImpTNTotal
2CH597Perez Renée124723231718990
3PH12Jean Pierre25422221417883
4124Dupuy Francois36921211516881
5236Guillot Louis44421201415777
63413Hubert Joseph54B20241514780
74522Boucher Pauline24231514581
85687Carpentier Antoine478F23221414780
96758Sanchez CharlesHUN2522211314777
107814Dupuis NicolasKLM2121211313775
118969Moulin EtienneGTR5421201213773
1291025Louis Guillaume1220201212771
13101198Deschamps Michel520201112770
14111232Huet Andre6519201112769
151213478220
161314147Perez RenéeBF450
171415258Boucher PaulineLO540
181598166Peters Léon0
Classe B
Cell Formulas
RangeFormula
Q2:Q18Q2=SUM(F2:P2)


Sheets("Liste")

MaListe.xlsm
A
1Eleveurs
2Adam Philibert
3Aubry Toussaint
4Bertin Arthur
5Boucher Pauline
6Bouvier Isidore
7Carpentier Antoine
8Carre Anthoine
9Charles Germain
10Charpentier Armand
11Collet Marius
12Deschamps Michel
13Dupuis Nicolas
14Dupuy Francois
15Fernandez Marin
16Fleury Auguste
17Guillot Louis
18Guyot Jehan
19Herve Olivier
20Hubert Joseph
21Huet Andre
22Jacquet Julien
23Jean Pierre
24Klein Georges
25Le Gall Baptiste
26Leger Elie
27Louis Guillaume
28Maillard Franciscus
29Marty Edmond
30Menard Constant
31Moulin Etienne
32Paris Fernand
33Perez Renée
34Peters Léon
35Renault Clement
36Royer Jules
37Sanchez Charles
38Schneider Daniel
Liste
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this:

VBA Code:
Sub list_names()
  Dim sh As Worksheet
  Dim c As Range
  Dim dic As Object
  Dim arr As Variant, itm As Variant
  Dim sNames As String
  
  arr = Array("Classe A", "Classe B", "Classe C", "Classe D", "Classe E", _
              "Classe F", "Classe AK", "Classe BK", "Classe CK", "Classe A4T", _
              "Classe B4T", "Classe C4T", "Classe AK4T", "Classe BK4T", "Classe CK4T")
  Set dic = CreateObject("Scripting.Dictionary")
  
  For Each itm In arr
    If Evaluate("ISREF('" & itm & "'!A1)") Then
      Set sh = Sheets(itm)
      For Each c In sh.Range("D2", sh.Range("D" & Rows.Count).End(3)).SpecialCells(xlVisible)
        If c.Value <> "" And Not c.HasFormula Then
          dic(c.Value) = Empty
        End If
      Next
    Else
      sNames = sNames & itm & vbCr
    End If
  Next
  
  With Sheets("Liste")
    .Range("A2:A" & Rows.Count).ClearContents
    .Range("A2").Resize(dic.Count).Value = Application.Transpose(dic.keys)
    .Range("A2").Resize(dic.Count).Sort .Range("A2"), xlAscending, Header:=xlNo
  End With
  
  If sNames <> "" Then
    MsgBox "These sheets do not exist:" & vbCr & sNames
  End If
End Sub

🤗
 
Upvote 0
Solution
Hello DanteAmor,
Thank you for your feedback and the proposed code, the latter works very well and meets my expectations.
Well done and thank you.
 
Upvote 0

Forum statistics

Threads
1,225,635
Messages
6,186,120
Members
453,340
Latest member
Stu61

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