Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Working down a column

Say I have a column starting at F5, it can be any length. The values in the
cells are numeric, some positive some negative. I want to look down the cells
and when I see the first change from a negative to a positive, I perform some
calculation using the values in that row. I then set 2 variables, one called
open, another called closed. Set open to true, closed to false. Keep looking
down the column and when the values switches from positive to negative and
open equals true and closed equal false, do some calculations. Keep doing
that until the end of the column. I am lost and need some help to get started
please? Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Working down a column

Hi Anita

Try the below and feedback..

Sub MyMacro()
Dim lngRow As Long, varTemp As Variant, varChange As Variant
For lngRow = 5 To Cells(Rows.Count, "F").End(xlUp).Row
varTemp = Range("F" & lngRow) 0
If varChange < vbNull And varChange < varTemp Then
varChange = varTemp
'-ve to +ve varChange=True, +ve to -ve varChange=False

'Do your calculations here

End If
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Anita" wrote:

Say I have a column starting at F5, it can be any length. The values in the
cells are numeric, some positive some negative. I want to look down the cells
and when I see the first change from a negative to a positive, I perform some
calculation using the values in that row. I then set 2 variables, one called
open, another called closed. Set open to true, closed to false. Keep looking
down the column and when the values switches from positive to negative and
open equals true and closed equal false, do some calculations. Keep doing
that until the end of the column. I am lost and need some help to get started
please? Thanks in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Working down a column

Thanks so much for that Jacob. Works exactly as it should and fast response!

"Jacob Skaria" wrote:

Hi Anita

Try the below and feedback..

Sub MyMacro()
Dim lngRow As Long, varTemp As Variant, varChange As Variant
For lngRow = 5 To Cells(Rows.Count, "F").End(xlUp).Row
varTemp = Range("F" & lngRow) 0
If varChange < vbNull And varChange < varTemp Then
varChange = varTemp
'-ve to +ve varChange=True, +ve to -ve varChange=False

'Do your calculations here

End If
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Anita" wrote:

Say I have a column starting at F5, it can be any length. The values in the
cells are numeric, some positive some negative. I want to look down the cells
and when I see the first change from a negative to a positive, I perform some
calculation using the values in that row. I then set 2 variables, one called
open, another called closed. Set open to true, closed to false. Keep looking
down the column and when the values switches from positive to negative and
open equals true and closed equal false, do some calculations. Keep doing
that until the end of the column. I am lost and need some help to get started
please? Thanks in advance.

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
Trying to transpose a row to a column - it is not working - help! MRAWLS Excel Worksheet Functions 4 December 10th 08 03:14 PM
Last Row in Column not working Terry Excel Programming 4 September 27th 07 07:43 PM
Working with one Column in a Named Range Steve Drenker[_5_] Excel Programming 5 April 15th 06 04:07 AM
Working out first and last column and row in a range Peter Rooney Excel Programming 6 April 28th 05 02:22 PM
working by column name Bryan[_11_] Excel Programming 1 August 15th 04 08:37 PM


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