VBA code please!

kidra98

New Member
Joined
Aug 18, 2021
Messages
5
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi VBA experts and looking for your kind help. I have a file with about 4000 lines and has some columns and I have given an example below the first set of data is good, 2nd set of data is not good, 3rd set of data is good and the fourth one is not good. Is there any way Excel can highlight looping through the title based on the condition 1-5 should be in sequence and based on the condition explained in column c? Is this possible either by conditional formatting or VBA code. Thank you very much for your help and time. Much appreciated.
 

Attachments

  • Screenshot 2021-11-16 181551.png
    Screenshot 2021-11-16 181551.png
    29.8 KB · Views: 10

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi and Welcome to MrExcel.

In your actual data, after the title "Apple" do you have a hyphen, the word "step" and a number?
Or do you only have "Apple"?


1637107225817.png
 
Upvote 0
Hi and Welcome to MrExcel.

In your actual data, after the title "Apple" do you have a hyphen, the word "step" and a number?
Or do you only have "Apple"?


View attachment 51407
Hi Dante,
Apologies for the late reply. Yes, I do have a hyphen and the word step and another column with step 1 and step 2, etc. This report is downloaded from the internal app of the company. Thank you for your reply and I appreciate your comments. have a great one. Regards
 
Upvote 0
Try this:

VBA Code:
Sub highlight_title()
  Dim stopen As Boolean, notok As Boolean
  Dim a As Variant, it As Variant
  Dim dic As Object
  Dim tit As String
  Dim i As Long
  
  Set dic = CreateObject("Scripting.Dictionary")
  dic.comparemode = vbTextCompare
  
  With Range("A1", Range("C" & Rows.Count).End(3))
    a = .Value
    .Interior.Color = xlNone
  End With
  
  For i = 2 To UBound(a, 1)
    If a(i, 1) <> "" Then
      tit = Split(a(i, 1), "-")(0)
      If Not dic.exists(tit) Then
        If LCase(a(i, 3)) = LCase("Open") Then stopen = True Else stopen = False
        dic(tit) = i & "|" & i & "|" & stopen & "|" & True
      Else
        stopen = Split(dic(tit), "|")(2)
        notok = Split(dic(tit), "|")(3)
        If stopen Then
          If LCase(a(i, 3)) = LCase("Completed") Then 'error
            dic(tit) = Split(dic(tit), "|")(0) & "|" & i & "|" & True & "|" & False
          Else
            dic(tit) = Split(dic(tit), "|")(0) & "|" & i & "|" & True & "|" & notok
          End If
        Else
          If LCase(a(i, 3)) = LCase("Open") Then stopen = True Else stopen = False
          dic(tit) = Split(dic(tit), "|")(0) & "|" & i & "|" & stopen & "|" & notok
        End If
      End If
    End If
  Next
  For Each it In dic.items
    If Split(it, "|")(3) = False Then
      Range("A" & Split(it, "|")(0) & ":A" & Split(it, "|")(1)).Interior.Color = vbYellow
    End If
  Next
End Sub
 
Upvote 0
Solution
Try this:

VBA Code:
Sub highlight_title()
  Dim stopen As Boolean, notok As Boolean
  Dim a As Variant, it As Variant
  Dim dic As Object
  Dim tit As String
  Dim i As Long
 
  Set dic = CreateObject("Scripting.Dictionary")
  dic.comparemode = vbTextCompare
 
  With Range("A1", Range("C" & Rows.Count).End(3))
    a = .Value
    .Interior.Color = xlNone
  End With
 
  For i = 2 To UBound(a, 1)
    If a(i, 1) <> "" Then
      tit = Split(a(i, 1), "-")(0)
      If Not dic.exists(tit) Then
        If LCase(a(i, 3)) = LCase("Open") Then stopen = True Else stopen = False
        dic(tit) = i & "|" & i & "|" & stopen & "|" & True
      Else
        stopen = Split(dic(tit), "|")(2)
        notok = Split(dic(tit), "|")(3)
        If stopen Then
          If LCase(a(i, 3)) = LCase("Completed") Then 'error
            dic(tit) = Split(dic(tit), "|")(0) & "|" & i & "|" & True & "|" & False
          Else
            dic(tit) = Split(dic(tit), "|")(0) & "|" & i & "|" & True & "|" & notok
          End If
        Else
          If LCase(a(i, 3)) = LCase("Open") Then stopen = True Else stopen = False
          dic(tit) = Split(dic(tit), "|")(0) & "|" & i & "|" & stopen & "|" & notok
        End If
      End If
    End If
  Next
  For Each it In dic.items
    If Split(it, "|")(3) = False Then
      Range("A" & Split(it, "|")(0) & ":A" & Split(it, "|")(1)).Interior.Color = vbYellow
    End If
  Next
End Sub
Th
 
Upvote 0
Thank you very much, Dante. I will try to run this code and will get back to you end of the day. Thank you, Sir, much appreciated.
 
Upvote 0
Hi Dante Sir,
Thank you very much, and it works perfectly and flawlessly. Much appreciate your time and help. Seriously it was crazy code and thank you.
 
Upvote 0
Hello Kidra, you marked your solution as an answer. You must mark the post that really solved your problem.

I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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