Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 577
Default Indent based on character length

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.


  #2   Report Post  
Posted to microsoft.public.excel.misc
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
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 577
Default Indent based on character length

Dave,

Thanks for your suggestions!

It appears that I may have mistated my intended need. Basically, what I need
the subroutine/macro to do is check the character length in A1:A6500. If
there is a value, then check for the length. If the length is greater than 1,
then indent based on the character length.

pseudocode:

Does a value for Cell:A1 exist?
If exists, check the length of the character
If the character length is 1, indent based on that value.

For example, the output would be:

A
AA
AAA
AAAA

or

1
1.1
1.1.1

Thanks again for your help!

"Dave Peterson" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Indent based on character length

The A's are indented like this:

String length Indent
-------- ------ ------
A 1 0
AA 2 1
AAA 3 2
AAAA 4 3

So each indent is one less than the length of the string.

The 1's are indented like this:

String length Indent
-------- ------ ------
1 1 0
1.1 3 1
1.1.1 5 2

So does this mean that dots should be ignored in the string?

A.A.A would be indented 2 (since its length ignoring the dots is 3).

So the question is a lot different <vbg:

Option Explicit
Sub TestMe()

Dim myRng As Range
Dim myStr As String
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
myStr = myCell.Value
myIndentLevel = Len(Replace(myStr, ".", "")) - 1

If myIndentLevel 15 Then
'change it to 15???
myIndentLevel = 15
End If

If myIndentLevel 0 Then
myCell.IndentLevel = myIndentLevel
End If
Next myCell
End Sub

This requires xl2k or higher (Replace was added in xl2k).

If you're using xl97, you can change this line:
myIndentLevel = Len(Replace(myStr, ".", "")) - 1
to
myIndentLevel = Len(application.substitute(myStr, ".", "")) - 1

Scott wrote:

Dave,

Thanks for your suggestions!

It appears that I may have mistated my intended need. Basically, what I need
the subroutine/macro to do is check the character length in A1:A6500. If
there is a value, then check for the length. If the length is greater than 1,
then indent based on the character length.

pseudocode:

Does a value for Cell:A1 exist?
If exists, check the length of the character
If the character length is 1, indent based on that value.

For example, the output would be:

A
AA
AAA
AAAA

or

1
1.1
1.1.1

Thanks again for your help!

"Dave Peterson" wrote:

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


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 577
Default Indent based on character length

This is EXACTLY what I was looking for!

Thanks for your time and expertise, it's greatly appreciated!



"Dave Peterson" wrote:

The A's are indented like this:

String length Indent
-------- ------ ------
A 1 0
AA 2 1
AAA 3 2
AAAA 4 3

So each indent is one less than the length of the string.

The 1's are indented like this:

String length Indent
-------- ------ ------
1 1 0
1.1 3 1
1.1.1 5 2

So does this mean that dots should be ignored in the string?

A.A.A would be indented 2 (since its length ignoring the dots is 3).

So the question is a lot different <vbg:

Option Explicit
Sub TestMe()

Dim myRng As Range
Dim myStr As String
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
myStr = myCell.Value
myIndentLevel = Len(Replace(myStr, ".", "")) - 1

If myIndentLevel 15 Then
'change it to 15???
myIndentLevel = 15
End If

If myIndentLevel 0 Then
myCell.IndentLevel = myIndentLevel
End If
Next myCell
End Sub

This requires xl2k or higher (Replace was added in xl2k).

If you're using xl97, you can change this line:
myIndentLevel = Len(Replace(myStr, ".", "")) - 1
to
myIndentLevel = Len(application.substitute(myStr, ".", "")) - 1

Scott wrote:

Dave,

Thanks for your suggestions!

It appears that I may have mistated my intended need. Basically, what I need
the subroutine/macro to do is check the character length in A1:A6500. If
there is a value, then check for the length. If the length is greater than 1,
then indent based on the character length.

pseudocode:

Does a value for Cell:A1 exist?
If exists, check the length of the character
If the character length is 1, indent based on that value.

For example, the output would be:

A
AA
AAA
AAAA

or

1
1.1
1.1.1

Thanks again for your help!

"Dave Peterson" wrote:

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


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Predefined Cell Character Length Matt Excel Worksheet Functions 4 March 5th 09 10:21 PM
Indent based on Entry JSnow Excel Discussion (Misc queries) 1 September 11th 08 05:29 PM
assigning character length in a cell Audrey Excel Discussion (Misc queries) 4 July 30th 06 04:40 PM
Find character when the length varies Rookie_User Excel Discussion (Misc queries) 3 April 12th 06 07:17 PM
length of character data Saravanan Excel Discussion (Misc queries) 2 December 19th 04 06:49 PM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"