Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default pick out arguments from formula

I need to compare arguments in a set of =sum formulae to find duplicated ones.

Eg i need to find cells with formulae such as =sum( a1;a2;a3;a4;a4) where an
argument is duplicated.

Is anything in VBA to return the arguments by number from a formula in a cell?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default pick out arguments from formula

Not directly. You could use the "split" function and then compare
elements of the array. First, I get the formula and split it to be
assigned to the variable "sArguements". This is an array variable
that would look like this:
sArguements(0)="=sum(a1"
sArguements(0)="a2"
sArguements(0)="a3"
sArguements(0)="a4"
sArguements(0)="a4)"
Then I strip out the portion of the formula up to the parenthesis and
the last parenthesis.
Finally, I compare each cell that's referenced by the formula to the
other cells referenced by the formula. It could be done more
efficiently than this, but I don't know if it would be worthwhile
(e.g., if you have a lot of cells in each sum function).
You'd have to take another track if you have references that cover
more than one cell, (i.e. a1:a3)

Public Function test1() As Boolean
Dim sFormula As String
Dim sArguements
Dim i As Integer, x As Integer
Dim bDuplicate As Boolean
bDuplicate = False
sFormula = ActiveSheet.Cells(5, 5).Formula
sArguements = Split(sFormula, ",")
For i = 0 To UBound(sArguements)
If InStr(1, sArguements(i), "(") < 0 Then
sArguements(i) = Mid(sArguements(i), InStr(1, sArguements
(i), "(") + 1, 999)
Else
If InStr(1, sArguements(i), ")") < 0 Then
sArguements(i) = Left(sArguements(i), InStr(1,
sArguements(i), ")") - 1)
End If
End If
Next i
For i = 0 To UBound(sArguements)
For x = 0 To UBound(sArguements)
If Not i = x Then
If sArguements(i) = sArguements(x) Then
bDuplicate = True
End If
End If
Next x
Next i
test1 = bDuplicate
End Function
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
Use a formula with 2 arguments Steved Excel Worksheet Functions 6 July 31st 09 10:21 AM
formula pick up formula from another cell automatically jjaylad Excel Worksheet Functions 1 July 30th 09 05:35 PM
arguments in a formula chrisbmo2000 Excel Discussion (Misc queries) 5 May 1st 08 08:17 AM
Formula to pick out, cut and paste sm Excel Worksheet Functions 1 November 28th 07 09:13 PM
How do I add more than 30 arguments in a formula wilsocm Excel Worksheet Functions 5 July 19th 07 07:19 AM


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