Solved

Excel If tests

Posted on 2016-10-20
10
67 Views
Last Modified: 2016-10-25
So, I would like to do some real Excel kung Fu.  I have to evaluate A LOT of excel documents.  The formatting has to be exactly right.  I want to make a tab that I can copy into the doc, that will run a bunch of tests to check the data and formatting.  

Like (For Exact match's) (this works fine)
=IF(A4=Sheet1!A2,"The Value is Exact","The value is NOT exact")

But the more complicated ones, I am not sure how to check;
Is this a Date in specific format mm/yyyy or mm/dd/yyyy
Is this a number
Is this a WHOLE number (no decimals) (FIXED)
           =IF(INT(SHEET1!L3)=SHEET1!L3,"Is a whole #","Is NOT a Whole #")
Is this a Number with 2 decimals
Does this start with a 'p'
Does this have a '.' (period) in it anyplace)
Does this SUM to 1000
Does A1= any value in a list (column or something)
Is the cell formatted as number/text/general

One last thing, when I copy to a new sheet, it keeps trying to reference the old file like;
=IF(A5=[20161020_Tester_Tab.xlsx]SHEET1!A1,"The Value is Exact","The value is NOT exact")

More awesome, How would I have it check MORE then just one value, but a whole set of values A3-(Last value)

Please save me days and weeks of work, and help me out :(
Thank you in advance!!
0
Comment
Question by:loftyworm
  • 5
  • 4
10 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 41853215
for a series of validations, you need to determine:
* a list of validation rules
* the sequence of validation rules

if the validation rules is too long, you would probably not able to enter all rules in the cell's formula, and hence you probably may do the validation in Macro function instead. and then call it when you want to do the validation.

One last thing, when I copy to a new sheet, it keeps trying to reference the old file like;
that's the default behaviour how Excel works. You will need to change the formula manually if you want it to refer to the same workbook.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 41853282
I would suggest doing it in vba macro too. A bit harder if not familiar but would be portable to other sheets, just have it work down a range of cells or sheets.

Done if the above such as checking date formats and numbers with two decimal places etc are only related to the formatting if the cell as the data would be a date or number but could be formatted to show 21-oct. 21/10/16 or whatever and value of a number could be 1 but down as 1.00 or conversely 12.542575 but down as 13

How many checks are we talking here?

Steve
0
 
LVL 11

Author Comment

by:loftyworm
ID: 41853833
TY!!
Can I get some more direction on the specific macros.  I have zero experience with them (other then disabling them for security)

The tests will be 1 per cell, not all at once.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 41854027
Suggest give us a example sheet with some data in it and can give some examples.

Steve
0
 
LVL 11

Author Comment

by:loftyworm
ID: 41854051
Sure, one sec
0
 
LVL 11

Author Comment

by:loftyworm
ID: 41854113
Sorry about the delay, got called by boss.
Here is an example of what I need to test

Ideally (Open to suggestion) I would think I would take the tab, and copy it to the FILETOBETESTED.  I have had problems with this though, as the tab remembers the file name, so I may have to copy the data to the tester file.

I know how to do the color formatting so that all the TRUE values would be green, and all the bad values red.  I just need the tests.
C--Temp-Book1.xlsx
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 41854225
A quick example bit of VBA macro is below and attached in spreadsheet.  This runs down the cells you have selected and based on the column it checks for various formatted data.  In this case then colours them in red or green whether they pass or not but could do whatever else was needed.

You could have a master sheet which you paste the values into, you could point it at a data sheet and have it copy the data out as it is displayed and copy it... anything possible but depends more on what you want to do.  

At the moment it checks the value displayed in the cell (cell.text) rather than checking the actual value (cell.value) or how it is formatted.

Steve

Sub CheckData()

Dim myarea As Range
Dim ans As Integer
Dim CheckCell As Boolean
Set myarea = Selection.Cells

ans = MsgBox("You have highlighted " & myarea.Cells.Count & " cells.  Is this right to continue?", vbYesNo + vbQuestion + vbDefaultButton2, "CHECK WHICH CELLS")
If ans = 7 Then Exit Sub

For Each col In myarea.Columns
    For Each cell In col.Cells
        CheckCell = True
        Select Case cell.Column
            Case 2 ' Column B - check if specific strings
                Select Case cell.Text
                    Case "bob", "steve", "mary": CheckCell = True
                    Case Else: CheckCell = False
                End Select
           
            Case 3 ' Column C - check if mm/dd/yyyy format
                If Not cell.Text Like "##/##/####" Then CheckCell = False
               
            Case 4 ' Column D - check if specific string value
                Select Case cell.Text
                    Case "2Car1House", "1Car2House": CheckCell = True
                    Case Else: CheckCell = False
                End Select
           
            Case 6 ' Column F - check if Integer of value is same as value
                If Not cell.Text Like "*#" Then CheckCell = False
           
            Case 10 ' Column J - check if it looks like number pattern shown
                If Not cell.Text Like "*#.##" Then CheckCell = False
        End Select
        Select Case CheckCell
            Case False: cell.Interior.Color = 255
            Case True: cell.Interior.Color = 5296274
        End Select
    Next
Next

End Sub
C--Temp-Book1.xlsm
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 41859114
Thanks for choosing my answer but if you want any extra help or clarification just say.  There are lots of ways of doing things like this of course.

Steve
0
 
LVL 11

Author Comment

by:loftyworm
ID: 41859439
0
 
LVL 11

Author Comment

by:loftyworm
ID: 41859441
Oops, I think maybe you have!!  This is what I get for doing to many things at the same time
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Outlook Free & Paid Tools
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

776 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