Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ian Ian is offline
external usenet poster
 
Posts: 238
Default Conditional formatting

I'm having trouble setting conditional formats with VBA.

I currently have:

With
Worksheets(OPG).Range("D8").FormatConditions.Add(x lCellValue, xlNotBetween,
"=VALUE(LEFT(C8,4))", "=VALUE(RIGHT(C8,4))")
With .Font
.ColorIndex = 3
End With
End With

This gives Subscript out of range on the first line. C8 contains 2.94-3.06
and is a range of accepable values.

Ian
---


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Conditional formatting

Hi Ian,

Try something like:

Sub Tester()
Dim rng As Range
Dim var1 As Variant, var2 As Variant
Dim sh As Worksheet

Set sh = Worksheets(OPG)

Set rng = sh.Range("C8")

var1 = CDbl(Left(rng.Value, 4))
var2 = CDbl(Right(rng.Value, 4))

With rng(1, 2).FormatConditions
.Delete
.Add _
Type:=xlCellValue, _
Operator:=xlBetween, _
Formula1:=var1, _
Formula2:=var2
.Item(1).Font.ColorIndex = 46
End With

End Sub

---
Regards,
Norman


"Ian" wrote in message
...
I'm having trouble setting conditional formats with VBA.

I currently have:

With
Worksheets(OPG).Range("D8").FormatConditions.Add(x lCellValue,
xlNotBetween, "=VALUE(LEFT(C8,4))", "=VALUE(RIGHT(C8,4))")
With .Font
.ColorIndex = 3
End With
End With

This gives Subscript out of range on the first line. C8 contains 2.94-3.06
and is a range of accepable values.

Ian
---




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Conditional formatting

Hi Ian,

Additionaaly, if the worksheet name is OPG, then the line:

Set sh = Worksheets(OPG)


should be:

Set sh = Worksheets("OPG")


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Ian,

Try something like:

Sub Tester()
Dim rng As Range
Dim var1 As Variant, var2 As Variant
Dim sh As Worksheet

Set sh = Worksheets(OPG)

Set rng = sh.Range("C8")

var1 = CDbl(Left(rng.Value, 4))
var2 = CDbl(Right(rng.Value, 4))

With rng(1, 2).FormatConditions
.Delete
.Add _
Type:=xlCellValue, _
Operator:=xlBetween, _
Formula1:=var1, _
Formula2:=var2
.Item(1).Font.ColorIndex = 46
End With

End Sub

---
Regards,
Norman


"Ian" wrote in message
...
I'm having trouble setting conditional formats with VBA.

I currently have:

With
Worksheets(OPG).Range("D8").FormatConditions.Add(x lCellValue,
xlNotBetween, "=VALUE(LEFT(C8,4))", "=VALUE(RIGHT(C8,4))")
With .Font
.ColorIndex = 3
End With
End With

This gives Subscript out of range on the first line. C8 contains
2.94-3.06 and is a range of accepable values.

Ian
---






  #4   Report Post  
Posted to microsoft.public.excel.programming
Ian Ian is offline
external usenet poster
 
Posts: 238
Default Conditional formatting

Hi Norman

I tried your code, but it still fails. I get the same error as before, but
it appears on the "Set sh" line. The sheet name is definitely correct and I
tried it with the original designation (Sheet6), but get a type mismatch
error.

At least your method narrows it down, but I'm still unable to figure out
what's happening.

--
Ian
--
"Norman Jones" wrote in message
...
Hi Ian,

Try something like:

Sub Tester()
Dim rng As Range
Dim var1 As Variant, var2 As Variant
Dim sh As Worksheet

Set sh = Worksheets(OPG)

Set rng = sh.Range("C8")

var1 = CDbl(Left(rng.Value, 4))
var2 = CDbl(Right(rng.Value, 4))

With rng(1, 2).FormatConditions
.Delete
.Add _
Type:=xlCellValue, _
Operator:=xlBetween, _
Formula1:=var1, _
Formula2:=var2
.Item(1).Font.ColorIndex = 46
End With

End Sub

---
Regards,
Norman


"Ian" wrote in message
...
I'm having trouble setting conditional formats with VBA.

I currently have:

With
Worksheets(OPG).Range("D8").FormatConditions.Add(x lCellValue,
xlNotBetween, "=VALUE(LEFT(C8,4))", "=VALUE(RIGHT(C8,4))")
With .Font
.ColorIndex = 3
End With
End With

This gives Subscript out of range on the first line. C8 contains
2.94-3.06 and is a range of accepable values.

Ian
---






  #5   Report Post  
Posted to microsoft.public.excel.programming
Ian Ian is offline
external usenet poster
 
Posts: 238
Default Conditional formatting

Brilliant, thanks Norman. This was alos the problem with my original line.
All working well, now.

--
Ian
--
"Norman Jones" wrote in message
...
Hi Ian,

Additionaaly, if the worksheet name is OPG, then the line:

Set sh = Worksheets(OPG)


should be:

Set sh = Worksheets("OPG")


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Ian,

Try something like:

Sub Tester()
Dim rng As Range
Dim var1 As Variant, var2 As Variant
Dim sh As Worksheet

Set sh = Worksheets(OPG)

Set rng = sh.Range("C8")

var1 = CDbl(Left(rng.Value, 4))
var2 = CDbl(Right(rng.Value, 4))

With rng(1, 2).FormatConditions
.Delete
.Add _
Type:=xlCellValue, _
Operator:=xlBetween, _
Formula1:=var1, _
Formula2:=var2
.Item(1).Font.ColorIndex = 46
End With

End Sub

---
Regards,
Norman


"Ian" wrote in message
...
I'm having trouble setting conditional formats with VBA.

I currently have:

With
Worksheets(OPG).Range("D8").FormatConditions.Add(x lCellValue,
xlNotBetween, "=VALUE(LEFT(C8,4))", "=VALUE(RIGHT(C8,4))")
With .Font
.ColorIndex = 3
End With
End With

This gives Subscript out of range on the first line. C8 contains
2.94-3.06 and is a range of accepable values.

Ian
---








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I convert conditional formatting into explicit formatting? Patrick Harris Excel Discussion (Misc queries) 0 April 9th 09 12:00 AM
Formatting Conditional Formatting Icon Sets The Rook[_2_] Excel Discussion (Misc queries) 3 March 7th 09 08:48 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 0 January 15th 07 04:35 PM
Conditional Formatting that will display conditional data BrainFart Excel Worksheet Functions 1 September 13th 05 05:45 PM


All times are GMT +1. The time now is 02:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"