duplicate multiple columns at one

Ani_Excel

New Member
Joined
Apr 7, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have got 10 columns that I need to duplicate. I do not want to repeat the step 10 times but would like to have 1 entangled step. Is that possible by extending the Mcode?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Here is an example of duplicating only two columns but you can expand this to your 10

mock.xlsx
ABCDEFGH
1idfirst_namelast_nameemailgenderip_address
21GarethRicksongrickson0@gmpg.orgMale165.19.36.4
32DorthyAkiddakid1@blinklist.comFemale216.10.168.110
43BabSigarsbsigars2@dedecms.comFemale21.242.126.6
54JuniaBierlingjbierling3@economist.comFemale104.148.156.116
65DareenBotedbote4@google.deFemale36.133.6.150
76TateStrongitharmtstrongitharm5@shareasale.comFemale207.140.225.38
87MilliPoveleyempoveleye6@symantec.comFemale29.141.203.178
98CaseDuckworthcduckworth7@boston.comGenderfluid126.251.7.73
109FrancklynVearncombefvearncombe8@cyberchimps.comMale189.226.22.85
1110ZondraVidgeonzvidgeon9@bloglines.comFemale23.43.9.118
12
13idfirst_namelast_nameemailgenderip_addressfirst_name - Copylast_name - Copy
141GarethRicksongrickson0@gmpg.orgMale165.19.36.4GarethRickson
152DorthyAkiddakid1@blinklist.comFemale216.10.168.110DorthyAkid
163BabSigarsbsigars2@dedecms.comFemale21.242.126.6BabSigars
174JuniaBierlingjbierling3@economist.comFemale104.148.156.116JuniaBierling
185DareenBotedbote4@google.deFemale36.133.6.150DareenBote
196TateStrongitharmtstrongitharm5@shareasale.comFemale207.140.225.38TateStrongitharm
207MilliPoveleyempoveleye6@symantec.comFemale29.141.203.178MilliPoveleye
218CaseDuckworthcduckworth7@boston.comGenderfluid126.251.7.73CaseDuckworth
229FrancklynVearncombefvearncombe8@cyberchimps.comMale189.226.22.85FrancklynVearncombe
2310ZondraVidgeonzvidgeon9@bloglines.comFemale23.43.9.118ZondraVidgeon
data


and here is the Mcode
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"first_name", type text}, {"last_name", type text}, {"email", type text}, {"gender", type text}}),
    table_duplicated = List.Accumulate({"first_name", "last_name"}, #"Changed Type", (state as table, current as text) => 
    Table.DuplicateColumn(state, current, current & " - Copy")
)
in
    table_duplicated
 
Upvote 1
Here is an alternative solution

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"first_name", type text}, {"last_name", type text}, {"email", type text}, {"gender", type text}}),
    DC = Table.AddColumn(#"Changed Type", "duplicated", each [NewFirst = [first_name],NewLast = [last_name]]),
    ER=Table.ExpandRecordColumn(DC, "duplicated", {"NewFirst", "NewLast"}, {"NewFirst", "NewLast"})
in
    ER
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,573
Members
452,652
Latest member
eduedu

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