Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Best way to indent one column based on another

FYI -- I have done a fair amount of VBA but this is my first foray int
excel.

I have a workbook with N sheets (1-5). Each sheet has a differen
number of rows. Column A has a number. I want to toggle the inden
level of Column B on all rows on all sheets to the value found i
Column A or to 0. I assume I can do this in a subprogram fired from
macro -- maybe use a global variable to hold the indent on/off state s
the subprogram knows what to do.

What's the best way to loop over the data containing rows on each shee
and set this value? Setting the value is obviously easy but I haven'
been able to figure out loop parameters, etc. to make this go.

Any help or direction would be greatly appreciated! Thanks

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Excel VBA - Best way to indent one column based on another

Maybe:

Option Explicit
Sub testme01()

Dim wks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim myIndentLevel As Long

For Each wks In ActiveWorkbook.Worksheets
With wks
FirstRow = 2 'header row in 1???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = FirstRow To LastRow
myIndentLevel = 0
With .Cells(iRow, "A")
If IsNumeric(.Value) Then
If .Value < 16 _
And .Value 0 Then
myIndentLevel = CLng(.Value)
End If
End If
.Offset(0, 1).IndentLevel = myIndentLevel
End With
Next iRow
End With
Next wks
End Sub


"wrkoch <" wrote:

FYI -- I have done a fair amount of VBA but this is my first foray into
excel.

I have a workbook with N sheets (1-5). Each sheet has a different
number of rows. Column A has a number. I want to toggle the indent
level of Column B on all rows on all sheets to the value found in
Column A or to 0. I assume I can do this in a subprogram fired from a
macro -- maybe use a global variable to hold the indent on/off state so
the subprogram knows what to do.

What's the best way to loop over the data containing rows on each sheet
and set this value? Setting the value is obviously easy but I haven't
been able to figure out loop parameters, etc. to make this go.

Any help or direction would be greatly appreciated! Thanks!

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Best way to indent one column based on another

Thanks -- this will help a lot. The cell and range notation was no
very clear to me. Seeing your code explains a lot. And I was unawar
the there is a limit on the indent level

--
Message posted from http://www.ExcelForum.com

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
Indent based on character length Scott Excel Discussion (Misc queries) 4 July 20th 09 04:36 AM
Indent based on Entry JSnow Excel Discussion (Misc queries) 1 September 11th 08 05:29 PM
Filter text in a column by its Indent, to remove certain text 99TZ250 Excel Discussion (Misc queries) 1 May 21st 06 08:53 AM
how could I indent numbers in Excel? silviah Excel Discussion (Misc queries) 2 March 14th 06 12:16 AM
How do I indent a decimal aligned column from the margin? ChSp Excel Discussion (Misc queries) 1 December 1st 04 06:33 PM


All times are GMT +1. The time now is 09:46 PM.

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

About Us

"It's about Microsoft Excel"