Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do i compare values line by line??

Help:

I need to compare values line by line. The scenario is like this:
If A3.value = A2.value, go to next line and do another comparison
until next line is not equal to prev line's value.

but if A3.value not equal A2.value, insert a blank line in between. I
need to loop this until I get to a line where there is no value.

the number of line is NOT pre-determined.

can anybody help?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how do i compare values line by line??

Sub AddBlankLines()
Set rng = Range("A3")
Do
If rng.Value < rng.Offset(-1, 0).Value Then
rng.EntireRow.Insert
End If
Set rng = rng.Offset(1, 0)
Loop Until IsEmpty(rng)
End Sub

--
Regards,
Tom Ogilvy




projectside wrote in message
...
Help:

I need to compare values line by line. The scenario is like this:
If A3.value = A2.value, go to next line and do another comparison
until next line is not equal to prev line's value.

but if A3.value not equal A2.value, insert a blank line in between. I
need to loop this until I get to a line where there is no value.

the number of line is NOT pre-determined.

can anybody help?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do i compare values line by line??

thanks Tom for the immediate response.

now, after the blank row is inserted, how would i add a Total to
sub-total all the same items? In other words, how do I determine the
first cell and the last cell that belong to the same group?

e.g. I have

ITEM
apple 3
apple 2
apple 5

orange 1
orange 2
orange 4



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how do i compare values line by line??

Is there a reason you don't just use the built in SubTotal command under the
data menu. (not the subtotal worksheet function). It will do all this for
you plus provide outlining.

If you still need to code it post back.

--
Regards,
Tom Ogilvy


projectside wrote in message
...
thanks Tom for the immediate response.

now, after the blank row is inserted, how would i add a Total to
sub-total all the same items? In other words, how do I determine the
first cell and the last cell that belong to the same group?

e.g. I have

ITEM
apple 3
apple 2
apple 5

orange 1
orange 2
orange 4



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do i compare values line by line??

my sample only has 2 columns. the real file has infinite columns that I
need to total for each category.

apple 3 4 1 4 4 2 4 etc..
apple 4 5 5 5 5 5 2 etc...
etc..

Total 7 9 6 9 9 7 6 etc...

Orange 5 6 7 3 5 6
Orange 6 2 5 4 4 2


thanks Tom



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how do i compare values line by line??

Sub AddBlankLines()
Dim rng As Range, rng1 As Range
Dim col As Long
Set rng1 = Range("A2")
Set rng = Range("A3")
col = Cells(3, 256).End(xlToLeft).Column - 1
Do
If rng.Value < rng.Offset(-1, 0).Value Then
rng.EntireRow.Insert
Cells(rng.Row - 1, 2).Resize(1, col).Formula = _
"=Subtotal(9," & Range(rng1.Offset(0, 1), _
Cells(rng.Row - 2, 2)).Address(0, 0) & ")"
Set rng1 = rng
rng.Offset(-1, 0).Value = "Total " & _
rng.Offset(-2, 0).Value
rng.Offset(-1, 0).Font.Bold = True
End If
Set rng = rng.Offset(1, 0)
Loop Until IsEmpty(rng)
Set rng = rng.Offset(1, 0)
Cells(rng.Row - 1, 2).Resize(1, col).Formula = _
"=Subtotal(9," & Range(rng1.Offset(0, 1), _
Cells(rng.Row - 2, 2)).Address(0, 0) & ")"
rng.Offset(-1, 0).Value = "Total " & _
rng.Offset(-2, 0).Value
rng.Offset(-1, 0).Font.Bold = True

End Sub


--
Regards,
Tom Ogilvy

projectside wrote in message
...
yes i could have used that. but the thing is, the number of columns to
be summed varries from time to time.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly 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
How to convert a dotted line to a solid line in a line graph Sharlz Charts and Charting in Excel 1 January 14th 09 04:51 AM
average Line created in an existing line graph- based on one cell Melanie Charts and Charting in Excel 2 December 27th 07 09:14 PM
Compare a value and if is true copy the line to other worksheet Florian Excel Worksheet Functions 2 July 31st 07 09:36 PM
Make a line in a bar chart, and change color of any bars that exceed the line MarkM Excel Discussion (Misc queries) 4 July 5th 06 04:06 PM
coloring overy other line without doing so line by line gen Excel Worksheet Functions 5 April 1st 05 10:38 PM


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