VBA/macro/code for combined the name from multiple row

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
533
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
HI All,

Thanks in advance, we have the following sheet in excel and there is names in two or three rows, we want to combine them.

For example Code No. 763 (row 10) name in three rows, we want to make in one "UGC-Net/JRF/SET Teaching, Research, practice, numerical, 100 mock Aptitude (General Paper-1)"

We have many names this type in file. help pls.

Excel 2010 32 bit
B
C
2
Code​
Name
3
420​
U.G.C. NET/JRF/SET Teaching & Research
4
Aptitude (General Paper-I)
5
1553​
UGC-Net/JRF/SET Teaching & Research Aptitude (General Paper-1)
6
1588​
CSIR-UGC NET/JRF/SET Chemical Sciences
7
500​
CSIR-UGC NET/JRF/SET Physical Sciences
8
1551​
CSIR-UGC NET/JRF/SET Physical Sciences
9
1587​
CSIR-UGC NET/JRF/SLET Mathematical Sciences
10
763​
UGC-Net/JRF/SET Teaching, Research,
11
practice, numerical, 100 mock
12
Aptitude (General Paper-1)
13
894​
UGC NET/JRF/SET Computer Science and Applications (Paper II)
14
931​
UGC-NET/JRF/SLET Physical Education (Paper II)
15
317​
CSIR-UGC NET/JRF/SET Life Sciences
Sheet: Sheet1
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
How about
VBA Code:
Sub Vishaal()
   Dim Rng As Range
   
   With Range("B3:B" & Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks)
      For Each Rng In .Areas
         Rng.Offset(-1, 1).Resize(1).Value = Join(Application.Transpose(Rng.Offset(-1, 1).Resize(Rng.Count + 1).Value), " ")
      Next Rng
      .EntireRow.Delete
   End With
End Sub
 
Upvote 0
Its showing the following error

Run-time error '1004':

No cells were found

pls check and update.......


How about
VBA Code:
Sub Vishaal()
   Dim Rng As Range
  
   With Range("B3:B" & Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks)
      For Each Rng In .Areas
         Rng.Offset(-1, 1).Resize(1).Value = Join(Application.Transpose(Rng.Offset(-1, 1).Resize(Rng.Count + 1).Value), " ")
      Next Rng
      .EntireRow.Delete
   End With
End Sub
 
Upvote 0
Are the codes in col B starting on row 3 with the header on row 2?
 
Upvote 0
You can do this with Power Query. Copy paste didn't work with your OP, so I used fake data. Should work just the same.

Book1
ABCDE
1CodeNameCodeName
2AABCAABC 123
3123BX
4BXCCDE 345
5CCDE
6345
Sheet5


Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    ToText = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Name", type text}}),
    FilledDown = Table.FillDown(ToText,{"Code"}),
    Group = Table.Group(FilledDown, {"Code"}, {{"Name", each _, type table [Code=text, Name=anynonnull]}}),
    Combine = Table.TransformColumns(Group,{"Name", each Text.Combine(Table.Column(_,"Name")," ")})
in
    Combine
 
Upvote 0
maybe an alternative M-code ?
CodeNameCodeName
420U.G.C. NET/JRF/SET Teaching & Research420U.G.C. NET/JRF/SET Teaching & Research Aptitude (General Paper-I)
Aptitude (General Paper-I)1553UGC-Net/JRF/SET Teaching & Research Aptitude (General Paper-1)
1553UGC-Net/JRF/SET Teaching & Research Aptitude (General Paper-1)1588CSIR-UGC NET/JRF/SET Chemical Sciences
1588CSIR-UGC NET/JRF/SET Chemical Sciences500CSIR-UGC NET/JRF/SET Physical Sciences
500CSIR-UGC NET/JRF/SET Physical Sciences1551CSIR-UGC NET/JRF/SET Physical Sciences
1551CSIR-UGC NET/JRF/SET Physical Sciences1587CSIR-UGC NET/JRF/SLET Mathematical Sciences
1587CSIR-UGC NET/JRF/SLET Mathematical Sciences763UGC-Net/JRF/SET Teaching, Research, practice, numerical, 100 mock Aptitude (General Paper-1)
763UGC-Net/JRF/SET Teaching, Research,894UGC NET/JRF/SET Computer Science and Applications (Paper II)
practice, numerical, 100 mock931UGC-NET/JRF/SLET Physical Education (Paper II)
Aptitude (General Paper-1)317CSIR-UGC NET/JRF/SET Life Sciences
894UGC NET/JRF/SET Computer Science and Applications (Paper II)
931UGC-NET/JRF/SLET Physical Education (Paper II)
317CSIR-UGC NET/JRF/SET Life Sciences

Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Table.FillDown(Source,{"Code"}), {"Code"}, {{"Count", each _, type table}}),
    List = Table.AddColumn(Group, "Name", each Table.Column([Count],"Name")),
    Extract = Table.TransformColumns(List, {"Name", each Text.Combine(List.Transform(_, Text.From), " "), type text})
in
    Extract
 
Upvote 0
@lrobbo314
Copy paste didn't work with your OP
try this way
  1. copy table from the post
  2. paste into the sheet
  3. click the first cell of data (not header)
  4. click on the end of this value in formula bar
  5. shift +left arrow
  6. ctrl+c (non-printable character)
  7. select whole range
  8. Find/Replace copied something with nothing
 
Upvote 0

I went to follow your steps, and it pasted correctly right off the bat. I think I didn't have everything selected or something. All the rows were staggered and it looked really strange.

Thanks for the info though.
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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