VBA - Find value and overwrite it with the content of the cell above it

bnpdx

New Member
Joined
Jul 1, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello ;)

I hope you can help me with this.

I have a spreadsheet where columns D through M have cells with values "TARGET?".

I need VBA code that would do the following:
1) Find cells with these exact values (finding cells containing "TARGET?" is not enough as it can't be "TARGET? - BLAH"; it has to be exactly "TARGET?")
2) Overwrite the values in such cell with the content of the cell directly above it.
3) Mark new values (previously "TARGET?") using red font color.

Any help would be much appreciated.

Thank you!!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe this

VBA Code:
Sub t()
Dim fn As Range, loc As Range
    With ActiveSheet
        Set fn = Intersect(.UsedRange, .Range("D:M")).Find("Target?", , xlValues, xlWhole)
            If Not fn Is Nothing Then
               
                Do
                    Set loc = fn
                    If fn.Value = "Target?" Then
                    End If
                    Set fn = Intersect(.UsedRange, .Range("D:M")).FindNext(fn)
                    loc = loc.Offset(-1).Value
                    loc.Font.Color = vbRed
                Loop While Not fn Is Nothing
            End If
    End With
End Sub
 
Upvote 0
Maybe this

VBA Code:
Sub t()
Dim fn As Range, loc As Range
    With ActiveSheet
        Set fn = Intersect(.UsedRange, .Range("D:M")).Find("Target?", , xlValues, xlWhole)
            If Not fn Is Nothing Then
              
                Do
                    Set loc = fn
                    If fn.Value = "Target?" Then
                    End If
                    Set fn = Intersect(.UsedRange, .Range("D:M")).FindNext(fn)
                    loc = loc.Offset(-1).Value
                    loc.Font.Color = vbRed
                Loop While Not fn Is Nothing
            End If
    End With
End Sub

Thank you very much! This worked perfectly.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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