Solved

Checking & Validating Excel Formulas

Posted on 2012-03-15
9
259 Views
Last Modified: 2012-03-15
Hello Experts,

I need to establish some validation and checking rules for formulas in an Excel sheet.

Specifically, I need to check that the row number in a given formula is the same as the actual row of the cell containing the formula, and be able to raise a flag if not.

So what I really need is a way (or perhaps a function) for reading the row refered to in the formula

For example, applying this function on below formula will give me 16

=SUM(Sheet2!H16:J16)

Assuming the function is called GetRowNumber() and the formula is in Cell B16, I need to place a checking formula on the same row like this:

=If(GetRowNumber(B16) <> ActiveCell.Row(), "Mismatch Row in formula", "Formula is OK")

The above is my suggested way for validating my formulas, please feel free to offer a better approach or best practice (if you will)

Thank you,
Hani
0
Comment
Question by:Mehawitchi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 37724323
Do your formulas vary? Or are all they of the form SUM(A1:B1)?
0
 

Author Comment

by:Mehawitchi
ID: 37724415
Thank you Stephen for your query.

Below are 3 samples of the actual formulas:
=SUM(Corporate:Panorama!D57)
=SUM(Corporate:Panorama!E57)
=SUM(Corporate:Panorama!F65)

As you can see, only the column and row references vary, but the part "SUM(Corporate:Panorama!" is fixed.

Hope this helps.

Thanks again,
Hani
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 37724442
Hani - try this:
Function GetRowNumber(rIn As Range) As String

Dim s As String

s = rIn.Formula

With CreateObject("VBScript.RegExp")
    .Global = True
    .IgnoreCase = False
    .Pattern = "([A-Z]+)(\d+)"
    If CLng(.Execute(s)(0).Submatches(1)) = Application.Caller.Row Then
        GetRowNumber = "OK"
    Else
        GetRowNumber = "Wrong"
    End If
End With

End Function

Open in new window

So you would type =GetRowNumber(B16) in a cell etc.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Mehawitchi
ID: 37724573
Hi Stephen,

I don't think the function is working properly. The result is always "Wrong"  whether or not the formula is right.

I tried executing the "CLng(.Execute(s)(0).Submatches(1))" statement in the debugger's Immediate window but I'm getting a compilers error

Did it work at your end?
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 37724592
Yes worked for me. Can you post a small workbook?
0
 

Author Comment

by:Mehawitchi
ID: 37724638
Please check column "P" in "Total" sheet
Sample-File.xlsm
0
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 37724669
Try just changing line 10 to
.Pattern = "(\![A-Z]+)(\d+)"

Open in new window

0
 

Author Closing Comment

by:Mehawitchi
ID: 37724740
Thank you Stephan - It worked perfectly
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 37724747
My pleasure.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question