help with search and mark ,vba.

avishain

Board Regular
Joined
Dec 14, 2010
Messages
75
hello there,

im using excel 2007.

i got a pivot table from column A to G.

in that pivot table,column G consist of numbers,some are positive and some are negative.

i want to create a macro that will do the following:

i want it to take the number on the selected cell (column G) and find the oposite value (if i chose the cell which have 60 in it,i want to excel to find -60 ,if i chose -2,i want excel to find me the number 2)

so like i said,i want to color all the appropriate matches in red.

can anyone help?

thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Code:
Sub Highlight()
    Dim Found As Range, FirstFound As String
    Set Found = Range("A:G").Find(-ActiveCell.Value, , xlValues, xlWhole)
    If IsNumeric(ActiveCell.Value) Then
        If Not Found Is Nothing Then
            FirstFound = Found.Address
            Do
                Found.Interior.ColorIndex = 3   'Red
                Set Found = Range("A:G").FindNext(Found)
            Loop Until Found.Address = FirstFound
        Else
            MsgBox "No signed-complement match found for " & ActiveCell.Value
        End If
    End If
End Sub

Sub Highlight_Clear()
    Range("A:G").Interior.ColorIndex = xlNone
End Sub
 
Upvote 0
Code:
Sub Highlight()
    Dim Found As Range, FirstFound As String
    Set Found = Range("A:G").Find(-ActiveCell.Value, , xlValues, xlWhole)
    If IsNumeric(ActiveCell.Value) Then
        If Not Found Is Nothing Then
            FirstFound = Found.Address
            Do
                Found.Interior.ColorIndex = 3   'Red
                Set Found = Range("A:G").FindNext(Found)
            Loop Until Found.Address = FirstFound
        Else
            MsgBox "No signed-complement match found for " & ActiveCell.Value
        End If
    End If
End Sub
 
Sub Highlight_Clear()
    Range("A:G").Interior.ColorIndex = xlNone
End Sub


thank u very much,works perfect.

if i want to filter and see only the rows which have been painted in red,what should i do? (what code should i add).

cause i have like 3000 rows and i need scroll and i find the red cells and its very confusing...


i remind u again,its a pivot table:)
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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