Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. More VB and Excel (Groan!)

More VB and Excel (Groan!)

Scheduled Pinned Locked Moved Visual Basic
databasedata-structureshelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RichardGrimmer
    wrote on last edited by
    #1

    Hi guys (again!) Some of you may have been folowing my escapades with the Excel Object model, and many thanks to those that have offered assistance! So today's problem is as follows.... Have a column containing dates (Action dates). Each value in the column can be in either one of three states based on the values in two other date cols( Start date and End date). The values can either be accepted - i.e. between the two other dates, and therefore green, Not accepted, i.e. outside the dates and therefore Red, or Default - a value read from a SProc in an SQLServer db, and hence Blue. Now using conditional formatting, can use xlCellValue type, and compare based on the two cols for Accepted / Not accepted, and this seems to be OK, however, I cannot seem to make it work for the default values. I'm using the following code: strCondString = "=$I$" & CStr(lPos) & "=" & dtDefault With oWS.Cells(lPos, "I").FormatConditions.Add _ (Type:=xlExpression, Formula1:=strCondString) With .Font .Color = RGB(0, 0, 255) .Bold = True End With End With where lPos is a row reference, and dtDefault is the date. strCondString will evaluate to something like "=$I$2=12/01/2004" The code seems to get through the compiler, in that it doesn't throw any errors when steppping over, but also doesn't colour the text at all - it stays black.....anyone? To add confusion (and not looked at this bit yet), how will it all stack up when I throw in the colouring for Accepted - all default dates will be "accepted", so is there any precedence in the FormatConditions that anyone knows about? "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

    J 1 Reply Last reply
    0
    • R RichardGrimmer

      Hi guys (again!) Some of you may have been folowing my escapades with the Excel Object model, and many thanks to those that have offered assistance! So today's problem is as follows.... Have a column containing dates (Action dates). Each value in the column can be in either one of three states based on the values in two other date cols( Start date and End date). The values can either be accepted - i.e. between the two other dates, and therefore green, Not accepted, i.e. outside the dates and therefore Red, or Default - a value read from a SProc in an SQLServer db, and hence Blue. Now using conditional formatting, can use xlCellValue type, and compare based on the two cols for Accepted / Not accepted, and this seems to be OK, however, I cannot seem to make it work for the default values. I'm using the following code: strCondString = "=$I$" & CStr(lPos) & "=" & dtDefault With oWS.Cells(lPos, "I").FormatConditions.Add _ (Type:=xlExpression, Formula1:=strCondString) With .Font .Color = RGB(0, 0, 255) .Bold = True End With End With where lPos is a row reference, and dtDefault is the date. strCondString will evaluate to something like "=$I$2=12/01/2004" The code seems to get through the compiler, in that it doesn't throw any errors when steppping over, but also doesn't colour the text at all - it stays black.....anyone? To add confusion (and not looked at this bit yet), how will it all stack up when I throw in the colouring for Accepted - all default dates will be "accepted", so is there any precedence in the FormatConditions that anyone knows about? "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

      J Offline
      J Offline
      John Kuhn
      wrote on last edited by
      #2

      Instead of relying on Excel's FormatConditions to perform conditional formatting, couldn't you rely on conditional logic instead, like so?:

      Public Sub HighlightColor()
      Dim i As Integer
      For i = 1 To Range("MyRange").Rows.Count
      If Not (Cells(i, 8).Value <= Cells(i, 9).Value And Cells(i, 9).Value <= Cells(i, 10).Value) Then
      Cells(i, 9).Font.ColorIndex = 3 ' Red
      End If
      Next
      End Sub

      Or should the condition be in place for when someone interacts with the worksheet?

      R 1 Reply Last reply
      0
      • J John Kuhn

        Instead of relying on Excel's FormatConditions to perform conditional formatting, couldn't you rely on conditional logic instead, like so?:

        Public Sub HighlightColor()
        Dim i As Integer
        For i = 1 To Range("MyRange").Rows.Count
        If Not (Cells(i, 8).Value <= Cells(i, 9).Value And Cells(i, 9).Value <= Cells(i, 10).Value) Then
        Cells(i, 9).Font.ColorIndex = 3 ' Red
        End If
        Next
        End Sub

        Or should the condition be in place for when someone interacts with the worksheet?

        R Offline
        R Offline
        RichardGrimmer
        wrote on last edited by
        #3

        John Kuhn wrote: Or should the condition be in place for when someone interacts with the worksheet? Unfortunately, you've hit the nail on the head! Am developing a utility to generate the spreadsheets based on different date ranges, which will then be used by others to enter data - hence the need to have all the formatting stuff in place before the user gets the sheets - it's not just a VBA project, but a full VB6 executable. Have managed to get around it though, by putting the default dates into a hidden column, and then using xlCellValue rather than xlExpression. Many thanks for the help though - hope I can return the favour some day! "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

        S 1 Reply Last reply
        0
        • R RichardGrimmer

          John Kuhn wrote: Or should the condition be in place for when someone interacts with the worksheet? Unfortunately, you've hit the nail on the head! Am developing a utility to generate the spreadsheets based on different date ranges, which will then be used by others to enter data - hence the need to have all the formatting stuff in place before the user gets the sheets - it's not just a VBA project, but a full VB6 executable. Have managed to get around it though, by putting the default dates into a hidden column, and then using xlCellValue rather than xlExpression. Many thanks for the help though - hope I can return the favour some day! "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          You should have come to me, I could have got you the answer wholesale...:laugh: Steve S

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups