+ Reply to Thread
Results 1 to 2 of 2

Ignoring blank cells with data validation

Hybrid View

  1. #1
    Registered User
    Join Date
    10-05-2011
    Location
    Veenendaal, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    14

    Question Ignoring blank cells with data validation

    Hi guys,

    This might be a very easy one, i am not sure because i am a newb to vba.

    I have made vba code to look if the data i entered is correctly, but it gives an error with empty cells. So i am looking for code which ignores empty cells.

                    For Colcounter = 3 To 5
                    sCellValue = Worksheets("Ruwe_Data_Taken").Cells(counter, Colcounter)
                If IsDate(sCellValue) <> "Waar" Then
    '               Set the color of the cell with the value on red
                    Worksheets("Ruwe_Data_Taken").Cells(counter, Colcounter).Font.Color = RGB(255, 0, 0)
                    iErrorCounter = iErrorCounter + 1
                    iErrorsInRow = iErrorsInRow + 1
    This is the piece of code where it should ignore empty cells, thanks for any help!
    Last edited by worecx; 12-01-2011 at 07:44 AM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Ignoring blank cells with data validation

    worecx,

    Try checking if the cell is blank before checking if the cell contains a date:
        For Colcounter = 3 To 5
        scellvalue = Worksheets("Ruwe_Data_Taken").Cells(counter, Colcounter)
        If Trim(scellvalue) <> vbNullString Then
            If IsDate(scellvalue) <> "Waar" Then
                'Set the color of the cell with the value on red
                Worksheets("Ruwe_Data_Taken").Cells(counter, Colcounter).Font.Color = RGB(255, 0, 0)
                iErrorCounter = iErrorCounter + 1
                iErrorsInRow = iErrorsInRow + 1
            End If
        End If
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1