Sub Macro1()
'
Dim LR As Long 'Last Row
Dim LC As Long 'Last Column
Dim r As Range, c As Range
Dim msg As String, ans As Integer
LR = Cells.Find("*", [A1], xlFormulas, xlPart, xlByRows, xlPrevious, False, False).Row
LC = Cells.Find("*", [A1], xlFormulas, xlPart, xlByColumns, xlPrevious, False, False).Column
Set r = Range(Cells(1, 1), Cells(LR, LC))
For Each c In r
If c.Interior.ColorIndex = 15 Then
msg = "Cell " & c.Address & " is light grey."
ans = MsgBox(msg)
End If
Next c
End Sub
Sub Macro1()
'
Dim lRow As Long
Dim x As Long, a As Long
Dim c As Range
Dim booFound As Boolean
'Find last used cell in Column K and initialize variables.
'We don't want to use K:K because the range would take a
'long time to search in a loop routine.
lRow = Cells(Rows.Count, "K").End(xlUp).Row
x = 0
booFound = False
'---------------------------------------------------------
'Find first grey cell in the used cells of column K
Do While booFound = False And x<= lRow
x = x + 1
Set c = Cells(x, "K")
If c.Interior.ColorIndex = 15 Then
booFound = True
End If
Loop
'---------------------------------------------------------
'Assign row to variable a if grey cell is found
If booFound = False Then
MsgBox "No grey cells were found"
a = lRow
Else
a = c.Row
'reset variables
booFound = False
x = 0
End If
'---------------------------------------------------------
'For initial testing, this will select the cell so you can
'see the found cell. In the actual routine do not use this
'statement.
Cells(a, "K").Select
End Sub
grey cells.xls | |||||||
---|---|---|---|---|---|---|---|
J | K | L | M | N | |||
1 | ID | Type | Amount | Date | UserID | ||
2 | 2 | Other | 100 | 07/01/07 | AB | ||
3 | 4 | Other | 100 | 07/01/07 | AB | ||
4 | 5 | LATEINTERESTFEES:" | 50 | 07/01/07 | AB | ||
5 | 6 | INTERESTFEES:" | 25 | 07/01/07 | AB | ||
6 | 7 | Other | 100 | 07/10/07 | AB | ||
7 | 8 | Fees | 25 | 07/10/07 | AB | ||
8 | 9 | Other | 100 | 07/15/07 | AB | ||
Sheet1 |
Sub test()
Dim r As Range, ff As String, x As Range
Application.FindFormat.Interior.ColorIndex = 15
Set r = Cells.Find(What:="*", SearchFormat:=True)
If Not r Is Nothing Then
ff = r.Address
Do
If x Is Nothing Then
Set x = r
Else
Set x = Union(x, r)
End If
Set r = Cells.Find(What:="*",After:=r, SearchFormat:=True)
Loop Unitl ff = r.Address
Else
MsgBox "Not found"
End If
If Not x Is Nothing Then
MsgBox "Found" & vbLf & x.Address
x.Select
End If
End Sub
a = Application.WorksheetFunction.Match("L?TE*INTEREST*B*K*FEE*", Range("K:K"), 0)