Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Help with Excel Conditional Formatting Through VB.NET

Avatar of diablo089
diablo089Flag for United States of America asked on
Microsoft ExcelVisual Basic.NET
8 Comments1 Solution1407 ViewsLast Modified:
I have a conditional formatting formula that works fine in native Excel, but comes out weird when I use VB.NET to place it in a range of cells.

Here's the formula in native Excel 2007:

I set the applies to to this: =$B$5:$D$5,$J$5:$AC$5

So this works for what I'm trying to do: highlight columns B-D and J-AC of a single row if it is blank, and column I is not blank.

In VB.NET, to accomplish this I put the following code inside a loop that loops through the number of rows I want, where oBook is my workbook, and j is my loop counter

oBook.Sheets("PAD DATA").Range("B" & j & ":D" & j & ",J" & j & ":AC" & j).FormatConditions.Add(Type:=2, Formula1:="=AND(ISBLANK(B" & j & "), NOT(ISBLANK($I$" & j & ")))")
oBook.Sheets("PAD DATA").Range("B" & j & ":D" & j & ",J" & j & ":AC" & j).FormatConditions(1).Interior.PatternColorIndex = -4105
oBook.Sheets("PAD DATA").Range("B" & j & ":D" & j & ",J" & j & ":AC" & j).FormatConditions(1).Interior.ThemeColor = 10

When I run this in VB.NET, in Excel I get a conditional formatting formula of

So how can I get the formulas to come out the way it is when I add the conditional formatting natively in Excel? Should I try looping through each particular cell and adding conditional formatting to it? Also, is there an easier way to do this?
Avatar of nutsch
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers