#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default lines

hi,

lets say i have a sheet with like 40 rows in it. i want to group the rows
by account number. so i am curious if there is any code i could write to
group the account numbers, with a row between each group, and to see if there
is code i can write to draw a dotted line between each group.

thanks in advance,
geebee

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default lines

geebee, Copy the code below and paste it in a standard module.
Assumptions:
1. Account numbers are in column A
2. Row 1 is a header row
3. There are no blank rows in column A
4. The data is already sorted by column A
Does that help? James

Sub BreakAcctNbrs()
Dim k As Long, LastCol As Integer
LastCol = Cells(1, "iv").End(xlToLeft).Column
For k = Cells(Rows.Count, "a").End(xlUp).Row To 3 Step -1
If Cells(k, "a") < Cells(k - 1, "a") _
And Cells(k, "a") < "" And Cells(k - 1, "a") < "" Then
Rows(k).EntireRow.Insert
With Range(Cells(k, "a"), _
Cells(k, LastCol)).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
Next k
End Sub

"geebee" (noSPAMs) wrote in message
...
hi,

lets say i have a sheet with like 40 rows in it. i want to group the rows
by account number. so i am curious if there is any code i could write to
group the account numbers, with a row between each group, and to see if
there
is code i can write to draw a dotted line between each group.

thanks in advance,
geebee



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default lines

thanks. pretty slick. could you annotate the code. so that i can know what
each line is doing. im still learning VBA. and want to mke sure i understad
what each line is doing.



"Zone" wrote:

geebee, Copy the code below and paste it in a standard module.
Assumptions:
1. Account numbers are in column A
2. Row 1 is a header row
3. There are no blank rows in column A
4. The data is already sorted by column A
Does that help? James

Sub BreakAcctNbrs()
Dim k As Long, LastCol As Integer
LastCol = Cells(1, "iv").End(xlToLeft).Column
For k = Cells(Rows.Count, "a").End(xlUp).Row To 3 Step -1
If Cells(k, "a") < Cells(k - 1, "a") _
And Cells(k, "a") < "" And Cells(k - 1, "a") < "" Then
Rows(k).EntireRow.Insert
With Range(Cells(k, "a"), _
Cells(k, LastCol)).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
Next k
End Sub

"geebee" (noSPAMs) wrote in message
...
hi,

lets say i have a sheet with like 40 rows in it. i want to group the rows
by account number. so i am curious if there is any code i could write to
group the account numbers, with a row between each group, and to see if
there
is code i can write to draw a dotted line between each group.

thanks in advance,
geebee




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default lines

Ok, here you go.

Sub BreakAcctNbrs()
'Subroutine written on Excel 2003.
'Not intended for Excel 2007. Might work for Excel 2007
'if no columns past 256 (column IV) are used
'and no rows below 65536 are used.

'It is not necessary to dim variables unless you are using Option
Explicit
'However, it is a good idea to use Option Explicit to avoid similar
names
'like myvar, MyVar and myVar conflicting with each other.

'The remaining remarks refer to the line below the remark.

'Since k will refer to rows, a long type variable is needed.
'Since LastCol will refer to columns, an integer type is sufficient.
Dim k As Long, LastCol As Integer
'Since the heading row will probably end at the last used column,
'determine the last column in the heading row to see how far across
'the sheet the dashed line should go.
LastCol = Cells(1, "iv").End(xlToLeft).Column
'The following loop will be used to insert blank rows and dashed lines
'between account numbers. When inserting rows, always go from the
bottom
'of the sheet upward.
'Since row 1 is a heading row and the code in the loop looks at the
'line before the line referred to by k, it is only necessary to loop
'k up to 3.
For k = Cells(Rows.Count, "a").End(xlUp).Row To 3 Step -1
'if the cell in column A of the current row (row k) is different
'than the cell in column A of the row above, then insert a row
'and a dashed line. Check that column A isn't empty to avoid
'inserting unneeded rows on subequent runs.
If Cells(k, "a") < Cells(k - 1, "a") _
And Cells(k, "a") < "" And Cells(k - 1, "a") < "" Then
'insert a blank row above row k.
Rows(k).EntireRow.Insert
'Using the range statement variation Range(Cells,Cells)
'is handy to put the dashed line from column A to the last
'used column.
With Range(Cells(k, "a"), _
Cells(k, LastCol)).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
Next k
End Sub

"geebee" (noSPAMs) wrote in message
...
thanks. pretty slick. could you annotate the code. so that i can know
what
each line is doing. im still learning VBA. and want to mke sure i
understad
what each line is doing.



"Zone" wrote:

geebee, Copy the code below and paste it in a standard module.
Assumptions:
1. Account numbers are in column A
2. Row 1 is a header row
3. There are no blank rows in column A
4. The data is already sorted by column A
Does that help? James

Sub BreakAcctNbrs()
Dim k As Long, LastCol As Integer
LastCol = Cells(1, "iv").End(xlToLeft).Column
For k = Cells(Rows.Count, "a").End(xlUp).Row To 3 Step -1
If Cells(k, "a") < Cells(k - 1, "a") _
And Cells(k, "a") < "" And Cells(k - 1, "a") < "" Then
Rows(k).EntireRow.Insert
With Range(Cells(k, "a"), _
Cells(k, LastCol)).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
Next k
End Sub

"geebee" (noSPAMs) wrote in message
...
hi,

lets say i have a sheet with like 40 rows in it. i want to group the
rows
by account number. so i am curious if there is any code i could write
to
group the account numbers, with a row between each group, and to see if
there
is code i can write to draw a dotted line between each group.

thanks in advance,
geebee






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
In Excel 2007 chart with multiple lines, mouse doesn't track lines sfuelling Charts and Charting in Excel 1 August 19th 09 09:41 PM
inserted lines move how to place lines in proper cell? Deschi Excel Worksheet Functions 0 February 8th 09 01:15 PM
Sub to copy only result lines within formula range, omit null string lines Max Excel Programming 2 July 15th 07 04:21 AM
Inserting Lines or Copying lines with formulas but without data wnfisba Excel Discussion (Misc queries) 2 August 18th 06 04:41 PM
excel97 vba to append lines to text file overwriting last 2 lines Paul Excel Programming 1 November 6th 04 08:11 PM


All times are GMT +1. The time now is 03:52 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"