Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default At each change in data apply formula

Is there a function/ code that can look down a column and apply a formula
when there is a change in data. i know there is the subtotal function but
this does not work for my requirement. Using the following data I would want
to automatically look at where the data changes (in column A) and apply a
formula in another column (say Column B) for the same row. I would therefore
expect to apply the formula as per the following example to cells B1, B4, B5
and B9

Col A
row 1 AAA
row 2 AAA
row 3 AAA
row4 BBB
row5 CCC
row6 CCC
row7 CCC
row8 CCC
row9 DDD
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default At each change in data apply formula

Hi,

Put this in b2 and drag down. Replace MyFormula with the one you want to use

=IF(A2<A1,Myformula,"")

Mike

"Shon" wrote:

Is there a function/ code that can look down a column and apply a formula
when there is a change in data. i know there is the subtotal function but
this does not work for my requirement. Using the following data I would want
to automatically look at where the data changes (in column A) and apply a
formula in another column (say Column B) for the same row. I would therefore
expect to apply the formula as per the following example to cells B1, B4, B5
and B9

Col A
row 1 AAA
row 2 AAA
row 3 AAA
row4 BBB
row5 CCC
row6 CCC
row7 CCC
row8 CCC
row9 DDD

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default At each change in data apply formula

Hi Shon

Try the below formula in cell C1 and copy down as required....The formula
will return the count of unique items aganist the first item which appears in
ColA as below

=IF(ISERROR(OFFSET(A1,-1,)),COUNTIF(A:A,A1),IF(OR(A1="",
OFFSET(A1,-1,)=A1),"",COUNTIF(A:A,A1)))


Col A Col C
AAA 3
AAA
AAA
BBB 1
CCC 4
CCC
CCC
CCC
DDD 1


--
Jacob


"Shon" wrote:

Is there a function/ code that can look down a column and apply a formula
when there is a change in data. i know there is the subtotal function but
this does not work for my requirement. Using the following data I would want
to automatically look at where the data changes (in column A) and apply a
formula in another column (say Column B) for the same row. I would therefore
expect to apply the formula as per the following example to cells B1, B4, B5
and B9

Col A
row 1 AAA
row 2 AAA
row 3 AAA
row4 BBB
row5 CCC
row6 CCC
row7 CCC
row8 CCC
row9 DDD

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default At each change in data apply formula

Shon, if you are looking for VBA code then try the below

Sub MyMacro()
Dim lngRow As Long, varData As Variant
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If varData < Range("A" & lngRow) Then
'your code starts here----
MsgBox lngRow
'-------------------------
varData = Range("A" & lngRow)
End If
Next
End Sub



--
Jacob


"Jacob Skaria" wrote:

Hi Shon

Try the below formula in cell C1 and copy down as required....The formula
will return the count of unique items aganist the first item which appears in
ColA as below

=IF(ISERROR(OFFSET(A1,-1,)),COUNTIF(A:A,A1),IF(OR(A1="",
OFFSET(A1,-1,)=A1),"",COUNTIF(A:A,A1)))


Col A Col C
AAA 3
AAA
AAA
BBB 1
CCC 4
CCC
CCC
CCC
DDD 1


--
Jacob


"Shon" wrote:

Is there a function/ code that can look down a column and apply a formula
when there is a change in data. i know there is the subtotal function but
this does not work for my requirement. Using the following data I would want
to automatically look at where the data changes (in column A) and apply a
formula in another column (say Column B) for the same row. I would therefore
expect to apply the formula as per the following example to cells B1, B4, B5
and B9

Col A
row 1 AAA
row 2 AAA
row 3 AAA
row4 BBB
row5 CCC
row6 CCC
row7 CCC
row8 CCC
row9 DDD

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default At each change in data apply formula

What kind of formula? If you want to sum the values in those cells, try this:

Sub InsertAfterTextChange()
Do Until ActiveCell = Empty And ActiveCell.Offset(1) = Empty
If ActiveCell < ActiveCell.Offset(1) And ActiveCell < Empty And
ActiveCell.Offset(1) < Empty Then
ActiveCell.Offset(1).EntireRow.Insert

Dim rLastCell As Range
Dim rFirstSum As Range
Dim rLastSum As Range
Set rLastCell = Range("A" & Rows.Count).End(xlUp)
Set rFirstSum = Range("A1")
Do

If rFirstSum.Offset(1) = "" Then
rFirstSum.Offset(, 1).Formula = _
"=Sum(" & rFirstSum.Address & ")"
Set rFirstSum = rFirstSum.End(xlDown)
Else
Set rLastSum = rFirstSum.End(xlDown)
rLastSum.Offset(, 1).Formula = _
"=Sum(" & Range(rFirstSum, rLastSum).Address & ")"
Set rFirstSum = rLastSum.End(xlDown)
End If

Loop Until rFirstSum.Row = rLastCell.Row Or _
rLastSum.Row = rLastCell.Row


ActiveCell.Offset(2).Select
Else
ActiveCell.Offset(1).Select
End If
Loop
End Sub

Make sure you Activate Cell A1 before running code.

HTH,
Ryan--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Jacob Skaria" wrote:

Shon, if you are looking for VBA code then try the below

Sub MyMacro()
Dim lngRow As Long, varData As Variant
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If varData < Range("A" & lngRow) Then
'your code starts here----
MsgBox lngRow
'-------------------------
varData = Range("A" & lngRow)
End If
Next
End Sub



--
Jacob


"Jacob Skaria" wrote:

Hi Shon

Try the below formula in cell C1 and copy down as required....The formula
will return the count of unique items aganist the first item which appears in
ColA as below

=IF(ISERROR(OFFSET(A1,-1,)),COUNTIF(A:A,A1),IF(OR(A1="",
OFFSET(A1,-1,)=A1),"",COUNTIF(A:A,A1)))


Col A Col C
AAA 3
AAA
AAA
BBB 1
CCC 4
CCC
CCC
CCC
DDD 1


--
Jacob


"Shon" wrote:

Is there a function/ code that can look down a column and apply a formula
when there is a change in data. i know there is the subtotal function but
this does not work for my requirement. Using the following data I would want
to automatically look at where the data changes (in column A) and apply a
formula in another column (say Column B) for the same row. I would therefore
expect to apply the formula as per the following example to cells B1, B4, B5
and B9

Col A
row 1 AAA
row 2 AAA
row 3 AAA
row4 BBB
row5 CCC
row6 CCC
row7 CCC
row8 CCC
row9 DDD

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 use formula to decide when to apply TIME data validation Barbara T Excel Worksheet Functions 3 November 3rd 09 06:34 PM
formula to apply concatenation to successive rows of data Devo Excel Worksheet Functions 2 July 24th 06 05:42 PM
How do I apply the ROUNDUP formula to a range of calculated data IslandGreenHouse Excel Worksheet Functions 1 May 28th 05 10:12 PM
How do I apply a Function to a column of cells and change there va Froggy New Users to Excel 1 December 23rd 04 12:09 AM
Better way to apply change to column of values Tod Excel Programming 3 September 16th 04 07:14 PM


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