Copy and merge columns to new worksheet

weijianhk

New Member
Joined
Feb 27, 2015
Messages
18
I have a project I am working on for work. It involves 12 columns: Column A is the Country name (country name from A to Z), Column B is the country ID, Column C is the Subscriber count of a particular country. Column D, E and F, is the supplier name, cost, and conversion rate of a specific company called Yonitech. Column H, I and J are also the supplier name, cost and conversion rate of another specific company called Aliworld, Column K,L and M are also the supplier name, cost and conversion rate of the third company called Lanck.

Basically, company Yonitech has supplier options for the countries that they can cover, with the cost and conversion rate listed. Likewise for company Aliworld and Lanck as well.
The supplier names of all 3 companies can be different.

I'm trying to write VBA codes to copy the information to another worksheet, information on the new worksheet would be the country name, country ID, subscriber count, as well as supplier name, cost and conversion rate. So what i'm trying to achieve is to copy paste the supplier names, cost and conversion of Yonitech into the new worksheet, and if cells are blank, it will then look through the supplier options of 2nd company Aliworld and copy paste the supplier names, cost and conversion of Aliworld before it similarly do the same for Lanck also.
So the new worksheet should only have 6 columns - country name, country ID, subscriber count, supplier name, cost and conversion rate, in which the last 3 columns are a combination of supplier options from the three companies.

Any help would be greatly appreciated. Thank you.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Instead of us having to type your data (guessing), please upload a sample of your data 8-10 records using XL2BB. Also then using XL2BB show us a mocked up solution. Be sure to use dummy names to protect confidentiality.
 
Upvote 0
Instead of us having to type your data (guessing), please upload a sample of your data 8-10 records using XL2BB. Also then using XL2BB show us a mocked up solution. Be sure to use dummy names to protect confidentiality.
Hi, I'm sorry for that and yeps I have attached the mockups.

Current -
Overall view_ Operator overview per Supplier Product_v1.9.xlsm
ABCDEFGHIJKLMNOP
2MccMncCountryRegionSubregionCM Op NameSubscriber CountMarket Share %Supplier product name CostConversion RateSupplier product name (1)Cost (1)Conversion Rate (1)Supplier product name (2)Cost (2)Conversion Rate (2)
341201AfghanistanAPACSouthern AsiaAF - AWCC 3,900,85620.09%MessageBird Direct0.0755
441220AfghanistanAPACSouthern AsiaAF - Roshan 6,203,70031.95%Antwerp Tech Direct0.089
541240AfghanistanAPACSouthern AsiaAF - MTN 4,535,78823.36%MessageBird Direct0.058
641250AfghanistanAPACSouthern AsiaAF - Etisalat 4,372,68622.52%Dexatel0.056
741288AfghanistanAPACSouthern AsiaAF - Afghan Telecom 219,4111.13%MessageBird Direct0.07
827602AlbaniaEuropeSouthern EuropeAL - Vodafone 1,021,49244.85%Apigate Axiata0.07429676486.56%
927601AlbaniaEuropeSouthern EuropeAL - Telekom Albania 1,016,02644.61%
1027603AlbaniaEuropeSouthern EuropeAL - Eagle 240,05610.54%Digicel Direct0.03357897979.47%
1160301AlgeriaMENAMENADZ - Mobilis 13,679,16042.63%Agile Telecom Directs0.079564.08%Dexatel0.0789
1260303AlgeriaMENAMENADZ - Nedjma 9,405,02429.31%Agile Telecom Directs0.05496460741.44%Agile Telecom Directs0.055
1360302AlgeriaMENAMENADZ - Djezzy 9,000,71428.05%Telxira0.062567.50%Agile Telecom Directs0.055
1454411American SamoaAPACPolynesiaAS - Bluesky 13,52444.25%SMS-MT0.035
1521303AndorraEuropeSouthern EuropeAD - Mobiland 63,587100.00%Mitto Direct0.0460.70%
Cost Compare
Cells with Data Validation
CellAllowCriteria
B3:B15CustomList


Expected output in a new worksheet -
Book3
ABCDEFGHIJ
1MccMncCountryRegionSubregionCM Op NameSubscriber CountMarket Share %Supplier product name CostConversion Rate
241201AfghanistanAPACSouthern AsiaAF - AWCC 3,900,85620.09%MessageBird Direct0.0755
341220AfghanistanAPACSouthern AsiaAF - Roshan 6,203,70031.95%Antwerp Tech Direct0.089
441240AfghanistanAPACSouthern AsiaAF - MTN 4,535,78823.36%MessageBird Direct0.058
541250AfghanistanAPACSouthern AsiaAF - Etisalat 4,372,68622.52%Dexatel0.056
641288AfghanistanAPACSouthern AsiaAF - Afghan Telecom 219,4111.13%MessageBird Direct0.07
727602AlbaniaEuropeSouthern EuropeAL - Vodafone 1,021,49244.85%Apigate Axiata0.07429786.56%
827601AlbaniaEuropeSouthern EuropeAL - Telekom Albania 1,016,02644.61%
927603AlbaniaEuropeSouthern EuropeAL - Eagle 240,05610.54%Digicel Direct0.03357979.47%
1060301AlgeriaMENAMENADZ - Mobilis 13,679,16042.63%Agile Telecom Directs0.079564.08%
1160303AlgeriaMENAMENADZ - Nedjma 9,405,02429.31%Agile Telecom Directs0.05496541.44%
1260302AlgeriaMENAMENADZ - Djezzy 9,000,71428.05%Telxira0.062567.50%
1354411American SamoaAPACPolynesiaAS - Bluesky 13,52444.25%
1421303AndorraEuropeSouthern EuropeAD - Mobiland 63,587100.00%Mitto Direct0.0460.70%
1563102AngolaAfricaMiddle AfricaAO - Unitel 10,503,68371.81%
Sheet1
Cells with Data Validation
CellAllowCriteria
B2:B15CustomList
 
Upvote 0
How about
VBA Code:
Sub weijianhk()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long
   
   With Sheets("Cost Compare")
      Ary = .Range("A2:P" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To 10)
   For r = 1 To UBound(Ary)
      For c = 1 To 7
         Nary(r, c) = Ary(r, c)
      Next c
      For c = 8 To 16 Step 3
         If Ary(r, c) <> "" Then
            Nary(r, 8) = Ary(r, c)
            Nary(r, 9) = Ary(r, c + 1)
            Nary(r, 10) = Ary(r, c + 2)
            Exit For
         End If
      Next c
   Next r
   Sheets("Sheet1").Range("A1").Resize(UBound(Ary), 10).Value = Nary
End Sub
 
Upvote 0
How about
VBA Code:
Sub weijianhk()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long
  
   With Sheets("Cost Compare")
      Ary = .Range("A2:P" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To 10)
   For r = 1 To UBound(Ary)
      For c = 1 To 7
         Nary(r, c) = Ary(r, c)
      Next c
      For c = 8 To 16 Step 3
         If Ary(r, c) <> "" Then
            Nary(r, 8) = Ary(r, c)
            Nary(r, 9) = Ary(r, c + 1)
            Nary(r, 10) = Ary(r, c + 2)
            Exit For
         End If
      Next c
   Next r
   Sheets("Sheet1").Range("A1").Resize(UBound(Ary), 10).Value = Nary
End Sub
Oh wow, you're a star! I'm really grateful for your fast turnaround and help, it works perfect!
I'm trying to understand the code, what is the main purpose of Ubound?

By the way, can you please kindly suggest how can I have a new column in the new worksheet which looks at the "weighted average" i.e. Cost * Market Share?

Thanks a ton!
 
Upvote 0
For the extra column use
VBA Code:
Sub weijianhk()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long
   
   With Sheets("lists")
      Ary = .Range("A2:P" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To 11)
   For r = 1 To UBound(Ary)
      For c = 1 To 7
         Nary(r, c) = Ary(r, c)
      Next c
      For c = 8 To 16 Step 3
         If Ary(r, c) <> "" Then
            Nary(r, 8) = Ary(r, c)
            Nary(r, 9) = Ary(r, c + 1)
            Nary(r, 10) = Ary(r, c + 2)
            If r > 1 Then Nary(r, 11) = Nary(r, 9) * Nary(r, 7)
            Exit For
         End If
      Next c
   Next r
   Sheets("Sheet1").Range("A1").Resize(UBound(Ary), 11).Value = Nary
End Sub
Ubound returns the upper bound of an array UBound function (Visual Basic for Applications)
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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