Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Comparing values in a cell and looping

I'm somewhat inexperienced at programming - just learning, but here is what I
would like to do.

I have a spreadsheet and in the first column I have different department
numbers. I have sorted by department number so all number that are the same
are together.

I would like to start out at cell (A6) and get the value of the cell and the
row number. I would then like to move to the next cell down and determine if
the value is the same as the previous cell or blank.

I would continue down the cells until the value in the tested cell is
different from the previous cell or cell A6. If the value is different, I
would like to add a row above that cell/row.

I would then want to use then want to record the different value and use it
as the test value and repeat the process until I get to last row of the
spreadsheet. This is a report so each report will have a different number
rows.

I know how to get the row number of a selected cell and the value of a
selected cell. I just don't know how to do the looping part. I've seen where
they define a range of cells but since each report will contain a different
number of records, not sure how I could do that.

Any help would be greatly appreciated.

Thanks
--
Michael Randall
Student
Keller Graduate School of Management
Masters of Information Systems Management
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Comparing values in a cell and looping

You will want to iterate the cells in Column A starting with the last data
row and proceed to the first data row. If you start from the first data row,
then every time you insert a row, you will "mess up" the loop counter's
tracking of the rows. Here is some code to do what you want...

Sub InsertBlankRows()
Dim X As Long, LastRow As Long
Const StartRow = 6
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For X = LastRow To StartRow Step -1
With Cells(X, "A")
If .Value < .Offset(-1).Value Then .Insert
End With
Next
End Sub

--
Rick (MVP - Excel)


"Michael_Randall" wrote in
message ...
I'm somewhat inexperienced at programming - just learning, but here is
what I
would like to do.

I have a spreadsheet and in the first column I have different department
numbers. I have sorted by department number so all number that are the
same
are together.

I would like to start out at cell (A6) and get the value of the cell and
the
row number. I would then like to move to the next cell down and determine
if
the value is the same as the previous cell or blank.

I would continue down the cells until the value in the tested cell is
different from the previous cell or cell A6. If the value is different, I
would like to add a row above that cell/row.

I would then want to use then want to record the different value and use
it
as the test value and repeat the process until I get to last row of the
spreadsheet. This is a report so each report will have a different number
rows.

I know how to get the row number of a selected cell and the value of a
selected cell. I just don't know how to do the looping part. I've seen
where
they define a range of cells but since each report will contain a
different
number of records, not sure how I could do that.

Any help would be greatly appreciated.

Thanks
--
Michael Randall
Student
Keller Graduate School of Management
Masters of Information Systems Management


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
Comparing Values from One Cell to Another EriccW Excel Programming 1 January 7th 09 11:19 PM
Faster Way of looping through cell values Andibevan Excel Discussion (Misc queries) 1 August 12th 05 03:10 PM
Looping and Testing Cell Values [email protected] Excel Programming 1 July 20th 05 04:29 PM
Comparing cell values Touk Excel Programming 3 September 29th 04 11:04 AM
Looping and Comparing values in two workbooks Lynn A. Excel Programming 1 September 15th 04 04:42 PM


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