Results 1 to 3 of 3
  1. #1
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402

    excel cells conditional formatting with access vba

    I am having some problems trying to add conditional formatting to my excel sheet via access vba
    I can add validation rules ok as below, but can't seem to convert the excel macro code created when setting up the cond/format rule.
    any help is appreciated.

    this works ok
    With Current_Worksheet.Range("F" & Mid(last_cell, 4, 3) + 2).Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=Sheet1!$A$1:$A$2"
    .IgnoreBlank = True
    .InCellDropdown = True
    .ShowInput = True
    .ShowError = True
    End With
    With Current_Worksheet.Range("$K8:K" & Mid(last_cell, 4, 3)).Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=sheet1!$A$4:$A$15"
    .IgnoreBlank = True
    .InCellDropdown = True
    .ShowInput = True
    .ShowError = True
    End With


    this is the macro from excel, can't seem to convert this in access vba code.

    Sub Macro2()
    ' Macro2 Macro
    Range("C8:F19").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN(TRIM(C8))=0"
    Selection.FormatConditions(Selection.FormatConditi ons.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = True
    End Sub

    i tried this but no go, it fails on first line of formatconditions. as this is not in the access lib?
    Current_Worksheet.Range("C8:F19").Select
    With Selection
    .FormatConditions.Add Type:=xlExpression, Formula1:="=LEN(TRIM(C8))=0"
    .FormatConditions(Selection.FormatConditions.Count ).SetFirstPriority
    .FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255


    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = True



  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    They are in the library, look in the VBA object browser.

    Possibly need parens around the Add arguments.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    I have solved it, thanks anyway.

    Current_Worksheet.Range("A8:F" & Mid(last_cell, 4, 3)).Select
    With Selection
    Current_Worksheet.Range("A8:F" & Mid(last_cell, 4, 3)).FormatConditions.Add Type:=xlExpression, Formula1:="=ISblank(A8:F" & Mid(last_cell, 4, 3)
    Current_Worksheet.Range("A8:F" & Mid(last_cell, 4, 3)).FormatConditions(1).Interior.Color = 255
    End With

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access Reports - Conditional Formatting
    By harpreett.singhh@gmail.co in forum Access
    Replies: 3
    Last Post: 08-07-2014, 02:38 PM
  2. Replies: 3
    Last Post: 07-01-2014, 10:10 AM
  3. Export query to Excel and apply conditional formatting
    By mcpearce in forum Import/Export Data
    Replies: 4
    Last Post: 04-27-2014, 05:26 PM
  4. Conditional Formatting in Access
    By Triland in forum Access
    Replies: 29
    Last Post: 01-18-2013, 01:00 PM
  5. Access Conditional formatting
    By mailboy in forum Access
    Replies: 1
    Last Post: 12-17-2011, 01:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums