View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Indent based on character length

Maybe...

Option Explicit
Sub TestMe()

Dim myRng As Range
Dim myCell As Range
Dim myIndentLevel

With Worksheets("Sheet1")
Set myRng = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In myRng.Cells
myIndentLevel = Len(myCell.Value) - 1
If myIndentLevel 15 Then
'change it to 15???
myIndentLevel = 15
End If
myCell.IndentLevel = myIndentLevel
Next myCell

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)


Scott wrote:

Does anyone know how to perform an indent based on the amount of characters
in the first cell.

In example: (not specific to 1, 10, 100)
If cell contains "1" (or any other one charachter length) then there is no
indent
If a cell contains "10" (or any other two length characters) then there is
one level of indentation
If a cell contains "100" (or any other three char length) then there is two
levels of indentation
.........

Thanks in advance.


--

Dave Peterson