Solved

Compare Excel Cell Styles

Posted on 2008-10-10
3
945 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now