how to find first and last instance

elmnas

Board Regular
Joined
Feb 20, 2015
Messages
206
Hello guys,


I have made following code

that check several statements..

if the value in column "H" have value"MLY" then check column if value is "I" if the value is "MLY" and if the value is more 0 in column "B" and "AB" same row.


For the same row but column "A" make a string of the value (myFound)

now my question:

from the value I want to find all occurrences in same column and make them a color.

see code

Code:
Sub mytest()




For i = 2 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
    If Cells(i, "H") = "MLY" And Cells(i, "I") = "MLY" And Len(Cells(i, "B")) <> 0 And Cells(i, "AB") <> 0 Then
   
   
   myFound= Cells(i, "A").Value
 
   End If
    
   Next i
   


End Sub

Could someone help me?

Thank you in advance
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You could do so with conditional formatting. Are you looking for a VBA approach to accomplish the same thing?
 
Upvote 0
Hi elmnas,

Code:
Sub mytest()


For i = 2 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
    
    If Cells(i, "H") = "MLY" And Cells(i, "I") = "MLY" And Len(Cells(i, "B")) <> 0 And Cells(i, "AB") <> 0 Then
   
   'myFound = Cells(i, "A").Value
   Cells(i, "A").Interior.Color = RGB(246, 160, 126)
 
   End If
    
   Next i


End Sub

Note:- Function:-RGB(Red,Green,Blue)

To Find Red,Green and Blue value for your color, go to Home -> Fill Color (Under Font Pane) -> More Colors -> Custom. and then select your color and find below the Red, Green and Blue number value for your color.

Thanks
Kashif
 
Upvote 0
Hi elmnas,

Code:
Sub mytest()


For i = 2 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
    
    If Cells(i, "H") = "MLY" And Cells(i, "I") = "MLY" And Len(Cells(i, "B")) <> 0 And Cells(i, "AB") <> 0 Then
   
   'myFound = Cells(i, "A").Value
   Cells(i, "A").Interior.Color = RGB(246, 160, 126)
 
   End If
    
   Next i


End Sub

Note:- Function:-RGB(Red,Green,Blue)

To Find Red,Green and Blue value for your color, go to Home -> Fill Color (Under Font Pane) -> More Colors -> Custom. and then select your color and find below the Red, Green and Blue number value for your color.

Thanks
Kashif


this is not what I am looking for........
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,271
Members
448,882
Latest member
Lorie1693

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