Moving Data in Cell

daigia_dzadzich

New Member
Joined
Jan 5, 2016
Messages
3
Hi,

I'm currently using excel 2010 & possibly upgrade to a later version in a near future. My question is that I currently have a large excel sheet with data look like below (Please note that the common fields are the member id & dependent associate id):

member Idnamedependent associate iddependent name
1Jim1Carol
2Todd2Sue
2Sam
3Chris3Kristy
3Aiden
3Isabella

<tbody>
</tbody>












What formula & syntax to move the data which have the end result looking like this:

member idnamedependent name 1dependent name 2dependent name 3
1JimCarolN/AN/A
2ToddSueSamN/A
3ChrisKristyAidenIsabella

<tbody>
</tbody>










Could you please help? Appreciate any inputs/assistants.

Thank you in advance,
Chris
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
daigia_dzadzich,

Welcome to the MrExcel forum.

1. What version of Windows are you using?

2. Are you using a PC or a Mac?

Here is a macro solution for you to consider, based on the fact that your raw data is sorted/grouped in column D.

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

Sample raw data, and, results:


Excel 2007
ABCDEFGHIJKL
1member Idnamedependent associate iddependent namemember IDnamedependent name 1dependent name 2dependent name 3
21Jim1Carol1JimCarolN/AN/A
32Todd2Sue2ToddSueSamN/A
42Sam3ChrisKristyAidenIsabella
53Chris3Kristy
63Aiden
73Isabella
8
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 ReorgData()
' hiker95, 01/05/2016, ME912210
Dim lr As Long, r As Long, nr As Long, nc As Long, lc As Long, n As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")   '<-- you can change the sheet name here
  .Range("G1").Resize(, 2).Value = Array("member ID", "name")
  nr = 2: nc = 9
  lr = .Cells(Rows.Count, 3).End(xlUp).Row
  For r = 2 To lr
    n = Application.CountIf(.Columns(3), .Cells(r, 3).Value)
    If n = 1 Then
      .Cells(nr, 7).Resize(, 2).Value = .Cells(r, 1).Resize(, 2).Value
      .Cells(nr, nc).Value = .Cells(r, 4).Value
    Else
      .Cells(nr, 7).Resize(, 2).Value = .Cells(r, 1).Resize(r, 1).Resize(, 2).Value
      .Cells(nr, nc).Resize(, n).Value = Application.Transpose(.Range(.Cells(r, 4), .Cells(r + n - 1, 4)).Value)
    End If
    nr = nr + 1
    r = r + n - 1
  Next r
  lc = .Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
  With .Cells(1, nc).Resize(, lc - 8)
    .Formula = "=""dependent name "" & Column() - 8"
    .Value = .Value
  End With
  On Error Resume Next
  .Range(.Cells(2, nc), .Cells(nr - 1, lc)).SpecialCells(xlCellTypeBlanks).Value = "N/A"
  .Columns(1).Resize(, lc).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 ReorgData macro.
 
Last edited:
Upvote 0
daigia_dzadzich,

Welcome to the MrExcel forum.

1. What version of Windows are you using?

2. Are you using a PC or a Mac?

Here is a macro solution for you to consider, based on the fact that your raw data is sorted/grouped in column D.

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

Sample raw data, and, results:

Excel 2007
ABCDEFGHIJKL
1member Idnamedependent associate iddependent namemember IDnamedependent name 1dependent name 2dependent name 3
21Jim1Carol1JimCarolN/AN/A
32Todd2Sue2ToddSueSamN/A
42Sam3ChrisKristyAidenIsabella
53Chris3Kristy
63Aiden
73Isabella
8

<tbody>
</tbody>
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 ReorgData()
' hiker95, 01/05/2016, ME912210
Dim lr As Long, r As Long, nr As Long, nc As Long, lc As Long, n As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")   '<-- you can change the sheet name here
  .Range("G1").Resize(, 2).Value = Array("member ID", "name")
  nr = 2: nc = 9
  lr = .Cells(Rows.Count, 3).End(xlUp).Row
  For r = 2 To lr
    n = Application.CountIf(.Columns(3), .Cells(r, 3).Value)
    If n = 1 Then
      .Cells(nr, 7).Resize(, 2).Value = .Cells(r, 1).Resize(, 2).Value
      .Cells(nr, nc).Value = .Cells(r, 4).Value
    Else
      .Cells(nr, 7).Resize(, 2).Value = .Cells(r, 1).Resize(r, 1).Resize(, 2).Value
      .Cells(nr, nc).Resize(, n).Value = Application.Transpose(.Range(.Cells(r, 4), .Cells(r + n - 1, 4)).Value)
    End If
    nr = nr + 1
    r = r + n - 1
  Next r
  lc = .Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
  With .Cells(1, nc).Resize(, lc - 8)
    .Formula = "=""dependent name "" & Column() - 8"
    .Value = .Value
  End With
  On Error Resume Next
  .Range(.Cells(2, nc), .Cells(nr - 1, lc)).SpecialCells(xlCellTypeBlanks).Value = "N/A"
  .Columns(1).Resize(, lc).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 ReorgData macro.

Thank you, Hiker95 for your feedback. I'm using Windows 7 & not familiar w/ the macro... sorry :(
I'm looking for a formula to enter into a cell & then drag it to other cells.

Thanks.
 
Upvote 0
Thank you, Hiker95 for your feedback. I'm using Windows 7 & not familiar w/ the macro... sorry

daigia_dzadzich,

Thanks for the feedback. You are welcome.

I'm looking for a formula to enter into a cell & then drag it to other cells.

Click on the Reply to Thread button, and just put the word BUMP in the thread. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
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