macro help

ed.ayers315

Board Regular
Joined
Dec 14, 2009
Messages
166
Hello Forum,

I found this searching threads and it works too well!

I want this macro to only work in selected cells, not the whole document.

Code:
Sub ReplaceCRLF()
  
  ActiveCell.Replace Chr(13), " ", xlPart  'x1Part apply to within cells (default)
  ActiveCell.Replace Chr(10) & Chr(10) & "N/A", " ", xlPart 'xlWhole apply to entire cell content
  
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Code:
Sub ReplaceCRLF()
Dim Rng As Range
    For Each Rng In Selection
        Rng.Replace Chr(13), " ", xlPart  'x1Part apply to within cells (default)
        Rng.Replace Chr(10) & Chr(10) & "N/A", " ", xlPart 'xlWhole apply to entire cell content
    Next Rng
End Sub

Try that out on a copy of your data.
 
Upvote 0
Code:
For Each oneCell in Selection
    oneCell.Value = Replace(Replace(oneCell.Value, vbCr, " "), vbLF & vbLF & "N/A", " ")
Next
Is the "N/A" that you are looking for actual text or an #N/A error value?
 
Upvote 0
Re: macro help (Solved)

Perfect, thank you.

And yes, looking for the text N/A and char(10)'s

Worked great!!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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