Consulting

Results 1 to 6 of 6

Thread: Format only blank cells in the range

  1. #1

    Format only blank cells in the range

    Dim cell As String
    With Range("Talk_Time")
        cell = .Cells(1, 1).Address(False, False)
        .Locked = False
        .NumberFormat = "hh:mm:ss"
        .Validation.Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, _
        Formula1:="=AND(" & cell & ">=TIME(0,0,1)," & cell & "<=TIME(23,59,59))"
        .Validation.IgnoreBlank = False
        .Validation.ErrorTitle = "Time Error"
        .Validation.ErrorMessage = "Please Enter Hours, Minutes & Seconds in this format 01:20:00"
        .Validation.ShowError = True
        .WrapText = False
        .ColumnWidth = 12
        .Interior.ColorIndex = 43
        .EntireColumn.Hidden = False
    End With
    my code, here works but only one problem I only want it to
     
    .NumberFormat = "hh:mm:ss"
    blank cells within range talktime.

    how can i do this ?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Untested

    Dim cell As String
    Dim rng As Range
    With Range("Talk_Time")
        cell = .Cells(1, 1).Address(False, False)
        .Locked = False
        On Error Resume Next
        Set rng = .SpecialCells(xlCellTypeBlanks)
        On Error GoTo 0
        If Not rng Is nothing Then rng.NumberFormat = "hh:mm:ss"
        .Validation.Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, _
        Formula1:="=AND(" & cell & ">=TIME(0,0,1)," & cell & "<=TIME(23,59,59))"
        .Validation.IgnoreBlank = False
        .Validation.ErrorTitle = "Time Error"
        .Validation.ErrorMessage = "Please Enter Hours, Minutes & Seconds in this format 01:20:00"
        .Validation.ShowError = True
        .WrapText = False
        .ColumnWidth = 12
        .Interior.ColorIndex = 43
        .EntireColumn.Hidden = False
    End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks will test it and get back to you

  4. #4
    works perfect thanks

  5. #5

    Angry A wonderful article

    A wonderful article…. In my life, I have never seen a man be so selfless in helping others around him to get along and get working.

  6. #6

    what?

    Don't talk in riddles spit it out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •