Strikethrough in Excel VBA

0 votes

When I enter the second date in a cell, I want the initial date to be strikethrough and keep both date in the same cell

I have a range of cells from column E to H, in which each cell has a date.

Your help would be highly appreciated

Sub ColorMeElmo()

'
Dim count As Long

count = ActiveSheet.Cells(Rows.count, "D").End(xlUp).Row

'
 
   Dim i As Long, r1 As Range, r2 As Range

   For i = 2 To count
     
      Set r1 = Range("D" & i)
      
      
        Set r2 = Range("E" & i)
     
      Dim diff1 As Long
      diff1 = DateDiff("D", r2.Value, r1.Value)
      
      If diff1 <= 5 Then r2.Interior.Color = vbRed
      If diff1 > 5 Then r2.Interior.Color = vbYellow
      
Next i

For ii = 2 To count
     
      Set r1 = Range("D" & ii)
      
      
        Set r2 = Range("F" & ii)
     
      Dim diff2 As Long
      diff2 = DateDiff("D", r2.Value, r1.Value)
      
      If diff2 <= 5 Then r2.Interior.Color = vbRed
      If diff2 > 5 Then r2.Interior.Color = vbYellow
      
End Sub

The range will change from D, E, F, G, and H. But here I give only E

Nov 27, 2022 in Others by Kithuzzz
• 28,700 points
70 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer

Language independent way to get "My Documents" folder in VBA Excel 2003

 Hello :)  This code may help you in your ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,630 points
150 views
0 votes
1 answer
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 53,160 points
1,142 views
0 votes
1 answer

Runtime error 438 while importing data in excel from secured website using VBA

Replace With ieDoc.forms(0) .userType.Value = "1" ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 53,160 points
195 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 53,160 points
233 views
0 votes
1 answer

Convert image (jpg) to base64 in Excel VBA?

Heres a function. Can't remember where I ...READ MORE

answered Sep 27, 2022 in Others by narikkadan
• 53,160 points
464 views
0 votes
1 answer

Can a worksheet ActiveX ComboBox work on a Mac?

ActiveX is an outdated Windows technology that ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 53,160 points
71 views
0 votes
1 answer

Excel VBA- Creation of a New datablock with criteria

To insert the dropdown, you can go ...READ MORE

answered Jan 12 in Others by narikkadan
• 53,160 points
36 views
0 votes
1 answer

I want to compare two Excel files and highlight the differences with VBA

The workbook doesn't have the UsedRange property ...READ MORE

answered Jan 13 in Others by narikkadan
• 53,160 points
51 views
0 votes
1 answer

VBA Export as PDF and Save to Location with name as per a Cell in the worksheet

Following is the code that gets generated ...READ MORE

answered Jan 20 in Others by narikkadan
• 53,160 points
50 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP