Transposing macro

SIGE

Board Regular
Joined
Oct 6, 2010
Messages
88
Hi,

I've a small problem that IMO can be easily fixed with VBA.

I've 2 datacolumns: A & B

in Column A I have different data but only 1 "key" identifier that should trigger my transpose job.
Ie. When I find eg. "SIGE" in column A (eg. A24) I would like it to transpose all data from A24 untill A34 and all data from B24 untill B34 going after the transposed data of column A. So acutally a "11x2"-range should become a "1x22"-range. (on a new sheet?)

Then the macro should go down to the next occurence of "SIGE" in column A and "transpose" the same 11x2 underneath the previous 1x22-result.

I hope some wizard can help me a hand on this one?

-There is 1 additional hitch: Can it do this procedure only when it finds exactly "SIGE" and not "SIGE 1" or "Sige"?

Desperately crossing fingers for your help, Sige
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
samle data is like thsi

Excel Workbook
AB
188308
249488
381324
447347
5SIGE272
659449
764446
826240
963328
1080368
1176449
1269307
1316359
1486289
1531305
1683295
17SIGE419
1820452
1978371
2099205
2153299
2266236
2385280
2463375
2577257
2676200
2746216
2855208
2981450
30SIGE443
3112461
3211486
3319354
3498300
Sheet1


try this macro and see whether you want like this (result in sheest2) data in sheet1

The string you refer to viz. SIGE take care of the spelling when you type into the input box. case does not matter because I made provision in hte macro about that.


Code:
Sub TEST()
Dim r As Range, cfind As Range
Dim x As String, add As String
x = InputBox("the string you want to find e.g. SIGE ")
Worksheets("sheet1").Select
With Columns("A:A")
Set cfind = .Cells.Find(What:=x, LookAt:=xlWhole, MatchCase:=False)
If Not cfind Is Nothing Then
add = cfind.Address
Range(cfind, cfind.Offset(10, 1)).Copy Worksheets("sheet2").Cells(Rows.Count, "A:A").End(xlUp).Offset(1, 0)
End If
Do
Set cfind = .Cells.FindNext(cfind)
If cfind Is Nothing Then Exit Do
If cfind.Address = add Then Exit Do
Range(cfind, cfind.Offset(10, 1)).Copy Worksheets("sheet2").Cells(Rows.Count, "A:A").End(xlUp).Offset(1, 0)
Loop
End With
End Sub


Code:
Sub undo()
Worksheets("sheet2").Cells.Clear
End Sub
 
Upvote 0
Hi Venkat,

Thank you for assistance. The macro is going in the right direction but it has 2 problems. Hopefully you can assist to remedy!

- The data /range is not getting "transposed",but just copied

In your example: Row1 in "sheet2" should become (over colums A / B / C /...)

SIGE / 59 / 64 / 26 / ... / 307 / 359 / 289

Row2:

SIGE / 20 / 78/ 99 / ... / 375 / 257 / 200
etc.

- For some obscure reason, the macro has skipped several good occurrences of "SIGE". I tried to figure out whether there are some invisible characters in those cells, but the "trigger cells" with "SIGE" appear to be identical...


Hope you can help me further!
Sige
 
Upvote 0
CLEAR the cells in sheet 2 and use this modified macro

Code:
Sub TEST()
Dim r As Range, cfind As Range
Dim x As String, add As String
x = InputBox("the string you want to find e.g. SIGE ")
Worksheets("sheet1").Select
With Columns("A:A")
Set cfind = .Cells.Find(What:=x, LookAt:=xlWhole, MatchCase:=False)
If Not cfind Is Nothing Then
add = cfind.Address
Range(cfind, cfind.Offset(10, 0)).Copy
Worksheets("sheet2").Cells(Rows.Count, "A:A").End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
Range(cfind.Offset(0, 1), cfind.Offset(10, 1)).Copy
Worksheets("sheet2").Cells(Rows.Count, "A").End(xlUp).End(xlToRight).PasteSpecial Transpose:=True
End If
Do
Set cfind = .Cells.FindNext(cfind)
If cfind Is Nothing Then Exit Do
If cfind.Address = add Then Exit Do
Range(cfind, cfind.Offset(10, 0)).Copy
Worksheets("sheet2").Cells(Rows.Count, "A:A").End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
Range(cfind.Offset(0, 1), cfind.Offset(10, 1)).Copy
Worksheets("sheet2").Cells(Rows.Count, "A").End(xlUp).End(xlToRight).PasteSpecial Transpose:=True
Loop
End With
Application.Cursor = False
End Sub

regading sige how do you check there are unnecessary characters or spaces. there is add in "cellview" which will give all the visible and invisible characters in a cell.

http://www.cpearson.com/excel/CellView.aspx

otherwise in one case of unrecognized sige just CLEAR the cell and then retype carefully without spaces etc and check.

of course you can also use trim function if it is only case of unnecessary spaces in the beginning and / or at the end olf sige.
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

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