Color the line when two dates are entered in the same line

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

Is it possible with VBA to color a line say grey when two dates are entered in the same line. So in my case "Vkp verwerkingsdatum" and "Ikp verwerkingsdatum"? So with one date entered nothing happens. The line should stay in the range of the table.

Thank you for your time.

Excel Formula:
Ingangs datum Meldings datumVerkoop ingangsdatumLeverancierProductgroepVerhoging inkoop %Verhoging verkoop %Vkp verwerkingsdatumIkp verwerkingsdatumVerwerkerNotitie
10/08/202231/05/202208/01/2022SVTBrandwerend18RomanoDiverse verhogingen
01/07/202212/05/202201/07/2022Coroplast29RomanoVerhoging XML VKP KP IKP zijn gepland
01/07/202225/05/202201/07/2022CPGdivers - zie prl G-schijf36Freek
01/07/202227/05/2022Sievert68
01/06/202201/06/202201/06/2022DucoRoosters19Freek
01/06/202202/05/202201/06/2022VitoPE celband/Vitoflex afstandh/Vitoseal26Shirley
01/06/202202/05/202201/06/2022VitoVitomount/Glazingmount/Vito BG1-2/Vitofix38Shirley
01/05/202221/04/202201/06/2022TPPRubber69Shirley
01/05/202222/04/2022Stokvistapes16Freek
01/05/202222/04/202201/05/2022CasteleinDow Sil28Freekinkoop nog aanpassen
01/05/202229/04/202201/05/2022Stokvisalles39
01/05/202231/03/202216/05/2022Bostik - Den BravenHybriden/MSP66Freekinkoop nog verwerken
01/05/202231/03/202216/05/2022Bostik - Den BravenVawa MSP18Freekinkoop nog verwerken
01/05/202231/03/202216/05/2022Bostik - Den BravenPUR schuim29Freekinkoop nog verwerken
01/05/202231/03/202216/05/2022Bostik - Den Bravenalles (m.u.v. Siliconen)36Freekinkoop nog verwerken
18/04/202206/04/202201/05/2022AdegoPU/PE Rondschuim68Shirley
11/04/202231/03/2022GSHKunststof19Romano
01/04/202201/02/2022CPGdivers - zie lijst26
01/04/202217/02/2022Rivafoamschuim PE/PU38Freek
01/04/202222/03/202201/04/2022Sikaalles69Joshua
21/03/202225/02/2022Bloemdivers - zie G schijf16Freek
14/03/202218/02/2022Decotric28Romano
11/03/202211/03/202211/03/2022Duco/GKL/ARDuco roosters39Freek
01/03/202216/01/202201/02/2022CoroplastAWX66RomanoAlles verwerkt
14/02/202214/02/202221/02/2022Fenoplastdivers - grondstoftoeslag18Freek
01/02/202204/11/202221/12/2022HenkelMS29Freek
01/02/202201/02/2022Otto ChemieS (siliconen)36Freek
01/02/202213/12/2022Otto ChemieM (hybride)68Freek
01/02/202217/01/2022CPGprijslijst per 1/feb - zie G schijf19Freek
01/02/202219/02/202219/01/2022Sika alles 26Joshua
01/02/202221/02/202201/05/2022ImpaWoodfill/All-Fill/Plastuk/Flexipox38Shirleyvooraankondiging 23-12-2021
01/02/202221/02/202201/05/2022ImpaCompa69Shirleyvooraankondiging 23-12-2021
01/02/202221/02/202201/05/2022ImpaDoseerapparaten Woodfill+All-Fill16Shirleyvooraankondiging 23-12-2021
17/01/202215/12/2021Connectacrylaat28Freekverkoopprijs checken
17/01/202215/12/2021Connectsilicone39Freekverkoopprijs checken
17/01/202215/12/2021ConnectMSP/Hybride66Freekverkoopprijs checken
17/01/202215/12/2021ConnectPU schuim18Freekverkoopprijs checken
02/01/202202/01/2022Bloemdivers - zie G schijf29Freek
01/01/202201/01/202228/02/2022VosschemieWoodcap repairs+polyester36Romano
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try the following macro, to be loaded into the vba class module of the working sheet:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim tbName As String, myC As Range, ColA As Object, ColB As Object
Dim myOff As Long
'
tbName = "TabellaOne"                                                           '<<< Name of the Table
Set ColA = Me.ListObjects(tbName).ListColumns("Vkp verwerkingsdatum").Range     '<<< Name of the Header 1
Set ColB = Me.ListObjects(tbName).ListColumns("Ikp verwerkingsdatum").Range     '<<< Name of the Header 2
'
For Each myC In Target
    If Not Application.Intersect(ColA, myC) Is Nothing Then
        myOff = 1
    ElseIf Not Application.Intersect(ColB, myC) Is Nothing Then
        myOff = -1
    Else
        myOff = 0
    End If
    If myOff <> 0 Then
        If IsDate(myC.Value) And IsDate(myC.Offset(0, myOff).Value) Then
            Application.Intersect(myC.EntireRow, Me.ListObjects(tbName).DataBodyRange).Interior.Color = RGB(200, 200, 200)
        Else
            Application.Intersect(myC.EntireRow, Me.ListObjects(tbName).DataBodyRange).Interior.Color = xlNone
        End If
    End If
Next myC
End Sub
To properly set the code:
-rightclick on the tab with the name of the sheet that contains the table; select Display code; this will open the vba editor at the right page
-copy the code and paste it into the empty frame
The 3 lines market <<< need to be customized with your data

Then return to excel and try typing or remiving dates into the "verwerkingsdatum" columns
 
Upvote 0
Another way... Again this should be loaded in the worksheet module of the worksheet where the table resides. Additionally, I used Sheet1 and Table1 as your object names- please change to fit your needs...

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim tbl As ListObject, i As Long
    Dim ws1 As Worksheet: Set ws1 = Worksheets("Sheet1")
    
    Application.ScreenUpdating = False
    Set tbl = ws1.ListObjects("Table1")
    If Intersect(Target, ws1.ListObjects("Table1").DataBodyRange) Is Nothing Then Exit Sub
    For i = 1 To tbl.ListRows.Count
        tbl.ListRows(i).Range.Interior.ColorIndex = 0
        If IsDate(tbl.DataBodyRange(i, 8)) And IsDate(tbl.DataBodyRange(i, 9)) Then
            tbl.ListRows(i).Range.Interior.ColorIndex = 15
        End If
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,699
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top