PDA

View Full Version : Solved: Conditional Formatting with VBA



traveler7739
09-26-2010, 06:05 AM
I have a worksheet that has several different named print ranges. The range that prints is determined by the values entered into two different cells on the worksheet. It's the combination of the two cells that determines which range should print. Is it possible to write a conditional statement in VBA to accomplish this?

Thank you!

Bob Phillips
09-26-2010, 06:36 AM
Probably. Give us the details.

traveler7739
09-26-2010, 06:54 AM
I entered an 'If, And' formula on the worksheet to come up with a single value derived from values entered into the two other cells I mentioned previously. I'm trying, with no success so far, to write in VBA an 'If, Then, Else' statement that will look at this single value and then print a named range based on that value? Any help you can provide will be greatly appreciated.

Thank you!!

Bob Phillips
09-26-2010, 07:23 AM
Show us the IF and worksheet formula at least.

traveler7739
09-26-2010, 08:10 AM
Here's what I have so far. Any help you can provide will be greatly appreciated.

Thank you!

IF(AND(InputBoxStyle="OLC",InputJoint="Tape"),"OLC-Tape","")

The 'InputBoxStyle' and 'InputJoint' are the two fields I referred to in my original posting. The result of this formula is the named range that I want to print. Here's the VBA code I've written so far:

Sub PrintProdForm

IF Cells(3,3).Value="OLC-Tape" Then

ActiveSheet.PageSetup.Orientation=xlLandscape
ActiveSheet.PageSetup.PrintArea="OLC-Tape"

ActiveSheet.PrintOut
Copies:=1
Preview:=True
ActivePrinter:="Epson Stylus Photo RX620"

Else

End Sub

Bob Phillips
09-26-2010, 10:27 AM
Sub PrintProdForm()

If Range("InputboxStyle").Value = "OLC" And Range("InputJoint").Value = "Tape" Then

'your code
End If

End Sub

traveler7739
09-26-2010, 11:05 AM
Thank you very much for your help!! You did a great job!

Thanks again!