View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Outlining based on level numbers in most left column

First, this needs xl2k or higher to run. It uses Replace that was added in
xl2k.

Second, I'm not sure how your data is laid out, but I created a test worksheet
with the data to be examined in column B. And I plopped the numbers into column
A. So don't use this without modifying the code or your data if it doesn't
match!

Option Explicit
Sub testme02()
Dim myCell As Range
Dim myRng As Range
Dim wks As Worksheet
Dim HowManyChars As Long
Dim WhatChars As Variant
Dim cCtr As Long

WhatChars = Array(".", "-")

Set wks = ActiveSheet

With wks
Set myRng = .Range("b1", .Cells(.Rows.Count, "B").End(xlUp))

For Each myCell In myRng.Cells
HowManyChars = 0
For cCtr = LBound(WhatChars) To UBound(WhatChars)
HowManyChars = HowManyChars _
+ (Len(myCell.Value) _
- Len(Replace(expression:=myCell.Value, _
Find:=WhatChars(cCtr), _
Replace:="", _
compa=vbTextCompare))) _
/ Len(WhatChars(cCtr))
Next cCtr
myCell.Offset(0, -1).Value = HowManyChars
Next myCell
End With

End Sub



Werner Rohrmoser wrote:

Hi,

I have a table, which is downloaded from SAP and has no formulas.
The identifier of the rows is a project item number like "PRD.
00133.07-03-04" and
I count the number of "." and "-" with a formula to get the level of
the project item.
My goal is now to make an outline by vba using the level numbers, e.g.
4 in the case
described above.
The first row of the table is poulate with these level numbers like
1
2
2
3
3
2
1
2 and so on.

Does anyone have a vba procedure to solve this problem.
Thanks.

Excel XP SP3
Windows XP SP3

Best Regards
Werner


--

Dave Peterson