Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50094

VBA find interior.color and display

$
0
0
Hello, I am new to vba coding and am trying to build a visual basic menu system on a 2003 excel spreed sheet.
At the moment I am stuck trying to figure out how to make a find search for only cells that are a particular interior color and then display the results in a list box, can someone help please.

Code:

Private Sub UserForm_Activate()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Sheet1
Set ws2 = Sheet2
Dim searchText As String, FirstAddr As String
Dim FoundCell As Range, LastCell As Range, searchRange As Range, cell As Range
Dim i As Long, endRow As Long
Dim foundTarget As Boolean

    'searchText = main.lblref.Text
    searchText = "0463"
 
    If Len(searchText) = 0 Then Exit Sub
 
    Application.ScreenUpdating = False
    Range("A6").End(xlDown).Select
    endRow = ActiveCell.Row
    Range("A6").Select
    Application.ScreenUpdating = True
           
    Set searchRange = ws2.Range("A6:A3000")
         
    Me.loanslist.Clear
    foundTarget = True
   
    With searchRange
        Set LastCell = .Cells(.Cells.Count)
    End With
         
    Set FoundCell = searchRange.Find(What:=searchText, After:=LastCell)
                     
    If Not FoundCell Is Nothing Then
        FirstAddr = FoundCell.Address
    Else
        foundTarget = False
    End If

    i = 0
    Do Until FoundCell Is Nothing
                                       
        'If FoundCell.Interior.color = 38 Then
   
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 11).Value & "    " & ws2.Cells(FoundCell.Row + 1, 11).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 12).Value & "    " & ws2.Cells(FoundCell.Row + 1, 12).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 13).Value & "    " & ws2.Cells(FoundCell.Row + 1, 13).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 14).Value & "    " & ws2.Cells(FoundCell.Row + 1, 14).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 15).Value & "    " & ws2.Cells(FoundCell.Row + 1, 15).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 16).Value & "    " & ws2.Cells(FoundCell.Row + 1, 16).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 17).Value & "    " & ws2.Cells(FoundCell.Row + 1, 17).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 18).Value & "    " & ws2.Cells(FoundCell.Row + 1, 18).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 19).Value & "    " & ws2.Cells(FoundCell.Row + 1, 19).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 20).Value & "    " & ws2.Cells(FoundCell.Row + 1, 20).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 21).Value & "    " & ws2.Cells(FoundCell.Row + 1, 21).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 22).Value & "    " & ws2.Cells(FoundCell.Row + 1, 22).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 23).Value & "    " & ws2.Cells(FoundCell.Row + 1, 23).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 24).Value & "    " & ws2.Cells(FoundCell.Row + 1, 24).Value
        Me.loanslist.AddItem ws2.Cells(FoundCell.Row, 25).Value & "    " & ws2.Cells(FoundCell.Row + 1, 25).Value
                   
        Set FoundCell = searchRange.FindNext(After:=FoundCell)
        If FoundCell.Address = FirstAddr Then
            Exit Do
        End If
        i = i + 1
       
    Loop
   
    If Not foundTarget Then
        MsgBox "No loans found for customer reference number " & searchText
    End If
       
    main.lblref.SetFocus
           
End Sub




So in short, how can I change the code to display data only from the found row's cell's that have a rose color fill?

I'm open to any other suggests also, thanks in advance, :)

Hally

Viewing all articles
Browse latest Browse all 50094

Trending Articles