Solved

Compare Excel Cell Styles

Posted on 2008-10-10
3
951 Views
Last Modified: 2012-06-21
VB2005, Excel 2007

I'm creating a VB.NET application that compares the contents of two Excel worksheets on a cell by cell basis.  I have not problem doing things like comparing values, formulas, number formats, etc.  What I want to be able to compare that the formatting on two cells is exactly the same.

What I have done so far is create an Excel style variable for each cell.

Dim ws1Style As Excel.Style = Worksheet1.Cells(r, c).style
Dim ws2Style As Excel.Style = Worksheet2.Cells(r, c).style

What I want to do now is determine if the two styles are exactly the same.  How can I do this?  
0
Comment
Question by:tfewster500
  • 2
3 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22687509
Hi tfewster500,

It won't work comparing Styles, I'm afraid. By default, all cells have the "Normal" style applied, regardless of the formatting applied. In general, Styles are used to apply specific formatting to a range of cells in a single operation, however, simply changing the font on a cell (using the Font property of the range) will have no effect on the Style.

You will need to compare each formatting property (Font, Borders, Interior, etc) of each cell seperately.

Regards,

Wayne
0
 
LVL 2

Expert Comment

by:madivad2
ID: 22692561
I'm not sure that this would work, I am away from my dev box so can't try it first, but if you created a custom class which populates just those cell formatting options you are interested in, then in the class initiation it could extract the relevant styles.

From there, it is a matter of comparing the classes to see if they are equal, remembering that the reference to the class will be different, but the comparative values will be the same. You could even write a custom method (of the class) to do this test for you
0
 
LVL 2

Accepted Solution

by:
madivad2 earned 500 total points
ID: 22692700
upon reflection, creating a class for just testing the styles is a bit of an overkill...

Just create your own method within your app that does the same thing, comparing the individual components of the style you'd like compared
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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

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