if, lookup, transpose? not sure...

MicJag

Board Regular
Joined
Oct 31, 2008
Messages
116
hi there, can someone please help me again.

i have 4 of the same equipment's in a1,2,3,4 but b1,2,3,4 each has a different movement type. is there a way i can get the movement type in c1, d1, e1 & f1 and at the end be able to remove duplicates in column A.

i have 700 000 rows to do this for :biggrin:

help is much appreciated

michael
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
MicJag,

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:
 
Upvote 0
oh sorry, its office 2010,


10000000 231
10000000 232
10000000 922
10000001 921
10000001 922
10000002 921
10000003 921
10000003 922
10000004 921
10000004 922
10000005 921
10000005 922
10000006 921
10000006 922
10000007 921
10000007 922

sorry im a bit slow here, thought the example explanation was good enough :biggrin:
 
Upvote 0
MicJag,

I would prefer not to have to separate your data into separate columns, and/or remove any space characters.

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:

If you are not able to give us screenshots, see below in my Signature block: You can upload your workbook to Box Net, and provide us with a link to your workbook.
 
Upvote 0
something like this? will this help?

Excel Workbook
AB
1EquipmentMvT1
210000000231
310000000232
410000000922
510000001921
610000001922
710000002921
810000003921
910000003922
1010000004921
1110000004922
1210000005921
1310000005922
1410000006921
1510000006922
Sheet1


Excel Workbook
DEFGHI
1EquipmentMvT1MvT2MvT3MvT4MvT5
210000000231232922**
310000001921922***
410000002921****
510000003921922***
610000004921922***
710000005921922***
810000006921922***
Sheet1
 
Upvote 0
MicJag,


Sample raw data in worksheet Sheet1 before the macro:


Excel Workbook
ABCDEFG
1EquipmentMvT1
210000000231
310000000232
410000000922
510000001921
610000001922
710000002921
810000003921
910000003922
1010000004921
1110000004922
1210000005921
1310000005922
1410000006921
1510000006922
1610000007921
1710000007922
18
Sheet1





After the macro:


Excel Workbook
ABCDEFG
1EquipmentMvT1EquipmentMvT1MvT2MvT3
21000000023110000000231232922
31000000023210000001921922
41000000092210000002921
51000000192110000003921922
61000000192210000004921922
71000000292110000005921922
81000000392110000006921922
91000000392210000007921922
1010000004921
1110000004922
1210000005921
1310000005922
1410000006921
1510000006922
1610000007921
1710000007922
18
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, by highlighting the code and pressing the keys CTRL + C
2. Open your 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 by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 07/22/2011
' http://www.mrexcel.com/forum/showthread.php?t=566243
Dim LR As Long, a As Long, SR As Long, ER As Long, LC As Long
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:B" & LR).Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
  , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
  False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
Columns(1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Columns(4), Unique:=True
LR = Cells(Rows.Count, 4).End(xlUp).Row
For a = 2 To LR Step 1
  SR = Application.Match(Cells(a, 4), Columns(1), 0)
  ER = Application.Match(Cells(a, 4), Columns(1), 1)
  If SR = ER Then
    Cells(a, 5).Value = Cells(SR, 2).Value
  Else
    Cells(a, 5).Resize(, ER - SR + 1).Value = Application.Transpose(Range("B" & SR & ":B" & ER).Value)
  End If
Next a
LC = Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
With Range(Cells(1, 5), Cells(1, LC))
  .Formula = "=""MvT"" & COLUMN()-4"
  .Value = .Value
End With
Range(Cells(1, 4), Cells(LR, LC)).Columns.AutoFit
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


Then run the ReorgData macro.
 
Upvote 0
sorry for all the trouble, i should learn how to get the questions out in the propper format here. :)

thank you very much for your help. thats why i love this forum :)
 
Upvote 0
Here is a none macro solution. adjust the range as needed

Excel Workbook
ABCDEFGH
1EquipmentMVT1SortedUnique List of Eqpmt.No. Occourances
210000000231100000003231232922
310000000232100000012921922
410000000922100000021921
510000001921100000032921922
610000001922100000042921922
710000002921100000052921922
810000003921100000062921922
910000003922100000072921922
1010000004921
1110000004922
1210000005921
1310000005922
1410000006921
1510000006922
1610000007921
1710000007922
Sheet2
 
Upvote 0
MicJag,


Same screenshots as my Reply #6.


The following should run a lot faster, especially since you have 700,000 plus rows.

I also assume that there are no blank rows in your data set. If there are, let me know and I will adjust the macro.


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, by highlighting the code and pressing the keys CTRL + C
2. Open your 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 by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgDataV2()
' hiker95, 07/22/2011
' http://www.mrexcel.com/forum/showthread.php?t=566320
' This macro code has been modified from the original code
'   by: mirabeau, 07/08/2011
'   http://www.mrexcel.com/forum/showthread.php?t=563070
Dim a, na As Long, m As Long, k As Long
Dim c(), p As Long, i As Long
i = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:B" & i).Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
  , Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
  Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
a = Range("A1").CurrentRegion.Resize(, 2)
na = UBound(a, 1)
m = 2
k = 1
ReDim c(1 To na, 1 To m)
For i = 2 To na
  If a(i, 1) <> a(i - 1, 1) Then
    k = k + 1
    p = 2
    c(k, 1) = a(i, 1)
    c(k, 2) = a(i, 2)
   Else
    p = p + 1
    If p > m Then
      m = p
      ReDim Preserve c(1 To na, 1 To m)
    End If
  c(k, p) = a(i, 2)
  End If
Next i
c(1, 1) = "Equipment"
For i = 2 To m
  c(1, i) = "MvT" & i - 1
Next i
With Range("D1").Resize(k, m)
  .Value = c
  .Columns.AutoFit
End With
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


Then run the ReorgDataV2 macro.
 
Last edited:
Upvote 0
Thank you once again hiker, this one works much faster, 1000 times faster than the first one. i don't have blank rows in the data,

much appreciated

i just added a VBA coarse to my annual KPI's. :biggrin:

regards
Mic
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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