Find/Replace Macro

Larcen60

New Member
Joined
Sep 12, 2017
Messages
18
Hello!

I'm trying to create a macro that does the following:

1. Find all instances of the value "#N/A" in Column C
2. When it finds "#N/A" in Column C compare the value in Column B of that same row to Column B of the row above it.
3. If Column B matches the Row above it, then copy Column C from that row into the Row below it.
4. If Column B does not match the row above it, highlight that row Blue.

Here is what the input would look like:

PolicyCompany NameClient Number
ABC123

<tbody>
</tbody>
Fake Company

<tbody>
</tbody>
45678

<tbody>
</tbody>
ABC123

<tbody>
</tbody>
Fake Company

<tbody>
</tbody>
#N/A
DEF456

<tbody>
</tbody>
Dummy Company

<tbody>
</tbody>
#N/A

<tbody>
</tbody>


And here's what I'm looking for the Output to look like:

PolicyCompany NameClient Number
ABC123Fake Company45678
ABC123Fake Company45678
DEF456Dummy Company#N/A

<tbody>
</tbody>


So far I have a loop that looks for all instances of "#N/A" and highlights if they don't match, but does anyone have any ideas of how I would code the "Find/Replace" part of that? Thanks very much for any help!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Here is another macro (using a completely different approach) that you can also consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub FixNAs()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "C").End(xlUp).Row
  Range("C2:C" & LastRow) = Evaluate(Replace(Replace(Replace("IF(ISNA(C2:C#),IF(B2:B#=B1:B@,C1:C@,IF(B2:B#=B3:B%,C3:C%,C2:C#)),C2:C#)", "#", LastRow), "@", LastRow - 1), "%", LastRow + 1))
  Intersect(Columns("C").SpecialCells([B][COLOR="#FF0000"]xlConstants[/COLOR][/B], xlErrors).EntireRow, ActiveSheet.UsedRange).Font.Color = vbBlue
End Sub[/td]
[/tr]
[/table]
NOTE: The above assume the #N/A in Column C are not produced from a formula. If they are produced from a formula, then change the red highlighted text to xlFormulas instead.
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,443
Members
449,453
Latest member
jayeshw

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