How to setup macro for data set

jakeman

Active Member
Joined
Apr 29, 2008
Messages
325
Office Version
  1. 365
Platform
  1. Windows
Hi there - I'm working with a data set that is in a less than friendly format. I'm trying to turn this data set into a more user friendly format for querying and pivot tables.

Here's how the data is currently structured:

Business EntityControl1Control2Control3Control4Control5Control6Control7Control8Control9Control10
LegalCntl_001Cntl_002
MarketingCntl_001Cntl_002Cntl_005
OperationsCntl_017Cntl_018
InvestmentsCntl_006Cntl_007

<tbody>
</tbody>










Instead of the above format, I'd like to write a macro that will step through each column where there is a control listed and if there is more than one control, it will append the Business Entity and the Control number to a new row. So I'd like my new list to look this way:

Business EntityControl #
LegalCntl_001
LegalCntl_002
MarketingCntl_001
MarketingCntl_002
MarketingCntl_005
OperationsCntl_017
OperationsCntl_018
InvestmentsCntl_006
InvestmentsCntl_007

<tbody>
</tbody>

















Can anyone share a method for this approach?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
try this

Code:
Sub Do_it2()

For r = 2 To Cells(Rows.Count, "A").End(xlUp).Row
For c = 2 To Cells(r, Columns.Count).End(xlToLeft).Column

With Worksheets("Sheet2")

lr = .Cells(Rows.Count, "A").End(xlUp).Row + 1
.Cells(lr, "A") = Cells(r, "A")
.Cells(lr, "B") = Cells(r, 2)
End With
Next c
Next r


End Sub
 
Upvote 0
Hey there - thanks for your response. I can't quite get this to work right.

Let's suppose that my data resides on a sheet called "Current_List" and the range of values begin on row 4 of column I to row 265 of column S. It would be ideal if I could empty the results of this macro to a sheet called Sheet2, where the data would begin on row 2 of that sheet. How would you revise your code to accommodate that change?

Thanks, man.
 
Upvote 0
Code:
Sub Do_it()

For r = 4 To Cells(Rows.Count, "I").End(xlUp).Row
For c = 10 To Cells(r, Columns.Count).End(xlToLeft).Column

With Worksheets("Sheet2")

lr = .Cells(Rows.Count, "A").End(xlUp).Row + 1
.Cells(lr, "A") = Cells(r, "I")
.Cells(lr, "B") = Cells(r, c)
End With
Next c
Next r


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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