Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compare Excel Cell Styles

Posted on 2008-10-10
3
Medium Priority
?
971 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

670 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