?
Solved

excel macro needed

Posted on 2005-05-09
6
Medium Priority
?
132 Views
Last Modified: 2010-05-02
I have a column in a spreadsheet in which the cells will have value one of the following :
m = male,f = female
m = male^f = female
Note that there is space after and before equal to sign.
I need a macro which will check for all the cells in the column so that there is space after and before equal to sign. If a space is not there then that cell should be colured in red.
0
Comment
Question by:michaelm702
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 13966114
Trusting that you have two equal signs in each cell:

    Dim v
    Dim r As Integer
   
    Const c = 1
    For r = 1 To ActiveSheet.UsedRange.Cells.Count
        v = Split(ActiveSheet.UsedRange.Cells(r, c), " = ")
        If UBound(v) < 2 Then
            ActiveSheet.UsedRange.Cells(r, c).Interior.ColorIndex = 3
        End If
    Next r
0
 

Author Comment

by:michaelm702
ID: 13966358
Each Cell does not have only two equal to signs there must be atleast one and any number greater than one. We should also check that each cell in that column has an equal to present aso.
0
 
LVL 81

Accepted Solution

by:
byundt earned 100 total points
ID: 13983426
michaelm702,
Try  using Conditional Formatting instead of a macro for your highlighting. To create Conditional Formatting, select all the cells that will receive the formatting, then open the Format...Conditional Formatting menu item.
Select "Formula Is" in the left field, then enter the following formula:
=NOT(ISERROR(FIND("=",SUBSTITUTE(A1," = ",""))))                   Formula assume that cell A1 is at top left corner of selected range

Click the Format button, then the Patterns tab. Choose your red highlight color, then click OK. Or else choose the Font tab and the red font color.

If the results don't appear quite right, check the Conditional Formatting formula to make sure that Excel didn't add extra quotes or absolute references in its zeal to be helpful. Correct any such errors, then click OK again.
Brad
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 100 total points
ID: 13985346
   Dim v
    Dim r As Integer
    Dim n as integer
    Const c = 1
    For r = 1 To ActiveSheet.UsedRange.Cells.Count
        v = Split(ActiveSheet.UsedRange.Cells(r, c), " = ")
        n = ubound(v, "=")
        If n < 1 then
             ActiveSheet.UsedRange.Cells(r, c).Interior.ColorIndex = 3
        Else
        v = Split(ActiveSheet.UsedRange.Cells(r, c), " = ")
        If UBound(v) < n Then
            ActiveSheet.UsedRange.Cells(r, c).Interior.ColorIndex = 3
        End If
End if
    Next r
0

Featured Post

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!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

750 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