?
Solved

VBA Excel 2010 - "Crosstab" in Excel

Posted on 2011-04-22
7
Medium Priority
?
316 Views
Last Modified: 2012-05-11
Dear Experts,

Can you please have a short look on the attached file, basically if somebody is familiar its a download from SAP, where items have stock on different storage locations, but being in a single field.

The pattern of it is always

1) text "SLOC"
2) number of the SLOC and ":"
3) stock
4) ","

So for example the cell "SLOC4:-2.947, SLOC3:201.121, SLOC1:3.414" means that item has minus 2.947 stock on SLOC4, stock 201.121 but on SLOC3, and 3.414 on SLOC1.

Could you advise whether with VBA or formula, is it possible to write some logic which would result as I did manually the C-D-E-F columns? So cutting the stock numbers out and putting under the certain SLOC column.

I assume rather it is complex but maybe someone has idea

thanks,
ExcelCrosstab.xls
0
Comment
Question by:csehz
7 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 668 total points
ID: 35447293
Is this What you want?

Sample Attached. I have written a Excel Function for you.

Sid

Code Used

Public Function GetSloc(rng As Range, rnglookup As Range) As Double
    Dim MyArray() As String, TempArray() As String
    
    On Error GoTo Whoa
    
    '~~> Check if there is more than 1 SLOC Value
    If InStr(1, rng.Value, ",") Then
        MyArray = Split(rng.Value, ",")
        For i = 0 To UBound(MyArray)
            If InStr(1, MyArray(i), rnglookup.Value, vbTextCompare) Then
                TempArray = Split(MyArray(i), ":")
                GetSloc = Val(TempArray(1))
                Exit Function
            End If
        Next i
    Else
        If InStr(1, rng.Value, rnglookup.Value, vbTextCompare) Then
            rng.Value = Replace(rng.Value, rnglookup.Value, "", , , vbTextCompare)
            GetSloc = Val(Trim(rng.Value))
        End If
    End If
Whoa:
End Function

Open in new window

ExcelCrosstab.xls
0
 
LVL 2

Assisted Solution

by:balatheexpert
balatheexpert earned 668 total points
ID: 35447338
here u go!!!!!!!!

use this formula!!!

Thanks,
Bala
Sap-Data.xls
0
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 664 total points
ID: 35447355
use this formula in c3 and copy it down and across

=IF(ISERR(FIND(C$1,$B2)),"",VALUE(MID($B2,FIND(C$1,$B2)+LEN(C$1)+1,IF(ISERROR(FIND(",",$B2,FIND(C$1,$B2))),LEN($B2)+1,FIND(",",$B2,FIND(C$1,$B2)))-FIND(C$1,$B2)-LEN(C$1)-1)))
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Closing Comment

by:csehz
ID: 35447433
This forum is amazing :-) From where I should have 1500 points? :-)))

I even almost did not have dare to put this question, and got three working solutions in so short and almost the same time. I think the fair to split the points as equal, thanks very much.

And Happy Easter too :-)
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35447439
Both the formulas with fail for values like

SLOC3:-9.32615623, SLOC2:93

Sid
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 35447471
How come Siddharth? it works fine with me.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35447500
My Mistake. Yeah you are right. I didn't autofit the columns. It was showing truncated values :)

Sid
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question