Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default change firstrow variable to be the 2nd row value instead of the fi


I think the only reason this macro doesn't work is because the first row is
a header row.
It took me awhile to figure it out. It compares, cells (irow, 16) =
(irow,16 -1) to see if it is a new deparment. If it doesn't match it is a
new department. It works on every row except the last one, the top row.
Since the first row is a header not a real line the first row count should
start on row 2. Can you help me fix this. I think after that it should
create a header row on every new department even the last one (2nd row).
THANKS,

-----
Public Sub ColorDivHeaders()

Dim firstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim sDeptName As String
Dim sStatusName As String
Dim sNextDeptID
Dim sDeptID
Dim rng As Range
With ActiveWorkbook.Worksheets("Sheet1")
firstRow = 2
LastRow = .Cells(.Rows.Count, 16).End(xlUp).Row
For iRow = LastRow To firstRow + 1 Step -1

sDeptID = .Cells(iRow, 16)
sNextDeptID = .Cells(iRow + 1, 16)
'first if block creates the Item Name headers


If .Cells(iRow, 16).Value = .Cells(iRow - 1, 16).Value Then

' if the department is the same as previous
'create the status headers


Else
'if the department is a new department add the row header
sDeptName = .Cells(iRow, 17).Value
.Rows(iRow).Insert
.Range(.Cells(iRow, 1), .Cells(iRow, 26)).Interior.ColorIndex = 15
.Cells(iRow, 3).Value = sDeptName

.Cells(iRow, 3).Font.Bold = True
.Cells(iRow, 3).Font.Size = 14
.Cells(iRow, 3).RowHeight = 18
End If
Next iRow


End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default change firstrow variable to be the 2nd row value instead of the fi

hey all, I found the problem on my own, sorry for the posts. The whole
problem I didn't see was the firstrow = 2 line.
I changed it to the
firstroww = 1 line and it works no, hacks.
Thanks,

"Janis" wrote:


I think the only reason this macro doesn't work is because the first row is
a header row.
It took me awhile to figure it out. It compares, cells (irow, 16) =
(irow,16 -1) to see if it is a new deparment. If it doesn't match it is a
new department. It works on every row except the last one, the top row.
Since the first row is a header not a real line the first row count should
start on row 2. Can you help me fix this. I think after that it should
create a header row on every new department even the last one (2nd row).
THANKS,

-----
Public Sub ColorDivHeaders()

Dim firstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim sDeptName As String
Dim sStatusName As String
Dim sNextDeptID
Dim sDeptID
Dim rng As Range
With ActiveWorkbook.Worksheets("Sheet1")
firstRow = 2
LastRow = .Cells(.Rows.Count, 16).End(xlUp).Row
For iRow = LastRow To firstRow + 1 Step -1

sDeptID = .Cells(iRow, 16)
sNextDeptID = .Cells(iRow + 1, 16)
'first if block creates the Item Name headers


If .Cells(iRow, 16).Value = .Cells(iRow - 1, 16).Value Then

' if the department is the same as previous
'create the status headers


Else
'if the department is a new department add the row header
sDeptName = .Cells(iRow, 17).Value
.Rows(iRow).Insert
.Range(.Cells(iRow, 1), .Cells(iRow, 26)).Interior.ColorIndex = 15
.Cells(iRow, 3).Value = sDeptName

.Cells(iRow, 3).Font.Bold = True
.Cells(iRow, 3).Font.Size = 14
.Cells(iRow, 3).RowHeight = 18
End If
Next iRow


End With
End Sub

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
Change variable permanently Arne Hegefors Excel Programming 4 August 28th 06 01:10 PM
change the number of rows to a variable minrufeng[_6_] Excel Programming 2 August 15th 05 10:03 PM
how to use object variable to change the property of a Fendic[_13_] Excel Programming 4 August 6th 05 07:12 PM
change function variable prompts?? thinkingfield Excel Worksheet Functions 1 November 8th 04 04:01 PM
change function variable prompts?? thinkingfield Excel Programming 0 November 7th 04 10:22 PM


All times are GMT +1. The time now is 09:39 AM.

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"