Transpose data in rows separated by common text

HC1987

New Member
Joined
Mar 30, 2015
Messages
6
Hi all,

I was wondering if it is possible to transpose data in rows, where each entry is separated by the same line of text. The problem for me is that each data entry contains different amount of rows for each company so cannot simply separate at every e.g. 6th row... Therefore, I need a macro that can recognize the standard line of text as a que for a new transposition. There is no spacing between the rows.

My data looks like this:

company name
address
phone
email
web
STANDARD LINE OF TEXT ("Biotech therapeutics")

I hope someone can help :)
 
HC1987,

Here is a macro solution for you to consider.

You can change the raw data worksheet name in the macro.

Sample raw data in column A, in Sheet1, and, the results in column C:


Excel 2007
ABC
1Company 1Company 1
2ACompany 2
3B
4C
5D
6E
7www.company1.de
8in the area of: Biotech Therapeutics & Diagnostics
9Company 2
10A2
11B2
12C2
13D2
14www.company2.de
15info@company2.de
16in the area of: Biotech Therapeutics & Diagnostics
17
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ExtractCompanyNames()
' hiker95, 03/30/2015, ME845481
Dim c As Range, nr As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")   ''<-- you can change the raw data sheet name here
  .Columns(3).ClearContents
  nr = 1
  .Cells(1, 1).Copy .Cells(nr, 3)
  For Each c In .Range("A2", .Range("A" & Rows.Count).End(xlUp).Offset(-1))
    If InStr(c, "Biotech Therapeutics") Then
      nr = nr + 1
      c.Offset(1).Copy .Cells(nr, 3)
    End If
  Next c
  .Columns(3).AutoFit
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the ExtractCompanyNames macro.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
HC1987,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,217,357
Messages
6,136,080
Members
449,989
Latest member
chrisgarcia78

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