+ Reply to Thread
Results 1 to 3 of 3

Loop thru subset of properties?

Hybrid View

  1. #1
    Registered User
    Join Date
    03-05-2009
    Location
    6500' in the Sierra Nevada
    MS-Off Ver
    Office 2007, 2010
    Posts
    74

    Loop thru subset of properties?

    I'm attempting to build a subroutine that compares a subset of font properties of two cells. What I have so far looks like this:
    Private Sub testFonts(ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, lngR, lngC, lngSumR)
    Dim property
    Dim aFonts
    aFonts = Array("Bold", " ColorIndex", " FontStyle", " Italic", " Name", " Size", " ThemeColor", " ThemeFont", " Underline")
    For Each property In aFonts
        If ws1.Cells(lngR, lngC).Font.property <> ws2.Cells(lngR, lngC).Font.property Then 
        End If
    Next
    End Sub
    Obviously, there is no property "property" of the Font object. What method, if any, can I use to test whether properties are identically set in the two cells?

    Many thanks.

    George

  2. #2
    Registered User
    Join Date
    03-05-2009
    Location
    6500' in the Sierra Nevada
    MS-Off Ver
    Office 2007, 2010
    Posts
    74

    Comparing workbooks

    I've assumed looping cannot be done so I made the comparisons explicit.

    The original problem was to compare a workbook submitted by a student to the "golden" workbook provided by the text book publisher. I teach a class in Excel at the local community college. Most assignments are from the text and involve a set of instructions on modifying a "starter" workbook. Ideally, following the instructions will result in a workbook virtually identical to the solution. The attached zip file contains a module for PERSONAL.xlsb and an associated user form. The module performs the comparison.

    The module requires that only two workbooks be open (in addition to the hidden PERSONAL workbook). It also requires that the workbooks have the same number of worksheets, and each worksheet has the same number of used rows and columns. (Within a workbook, worksheets may have different used ranges.) If these criteria are met a user form is presented with comparison options. One can then compare the workbooks for any combination of row height, column width, cell contents, formulas, number formats and fonts. If there is any difference between the workbooks a results workbook is created with an Excel table showing the address of the cell containing the difference, the property value for each workbook, and a reason code.

    Hope this helps someone.

    George
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    03-05-2009
    Location
    6500' in the Sierra Nevada
    MS-Off Ver
    Office 2007, 2010
    Posts
    74

    Re: Loop thru subset of properties?

    As it turns out, it is possible to loop through a subset of properties! Here some excerpts from my code. All that's really left out is the dimensioning & output

        strProps = "Name,Size,FontStyle,Underline"
        aPropNames = Split(strProps, ",")
        Set rng1 = ws1.UsedRange.Cells(lngr, lngc)
        Set rng2 = ws2.UsedRange.Cells(lngr, lngc)
        For Each strPropName In aPropNames
            varWS1 = CallByName(rng1.Font, strPropName, VbGet)
            varWS2 = CallByName(rng2.Font, strPropName, VbGet)
            If varWS1 <> varWS2 Then
                If Workbooks.Count = intWkbks Then addWorkbook
                str1 = strPropName & ": " & varWS1
                str2 = strPropName & ": " & varWS2
                If Len(strCell1) Then strCell1 = strCell1 & "; "
                If Len(strCell2) Then strCell2 = strCell2 & "; "
                strCell1 = strCell1 & str1
                strCell2 = strCell2 & str2
            End If
        Next
    Hope this helps someone.

    g

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1