ctrl+F?

xtscars

New Member
Joined
Apr 11, 2011
Messages
17
I would like to duplicate the find and replace function in a macro. I want to find all the zeros in my final column, and replace them with nothing, so they'll be blank.

I have my final column defined as: finalcolumn=range("xfd1").end(xltoleft).column

is there any code that will do this for me?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try This...
Code:
Sub replaceall()
'
' replaceall Macro
'

'
Dim finalcolumn As Long
Dim MyRange As Range

finalcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

Set MyRange = ActiveSheet.Range(Cells(1, finalcolumn), Cells(ActiveSheet.Rows.Count, finalcolumn))

MyRange.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End Sub
 
Upvote 0
I'm trying to use that, but it's saying there is a "Compile error: Invalid character" and it highlights that last "_" between "False," and "ReplaceFormat"...do you have any advice on this?

Thanks for the the help!
 
Upvote 0
I deleted the following. It wasn't necessary.
Code:
                                [COLOR=Red][B], _[/B]
[B]        ReplaceFormat:=False[/B][/COLOR]
Try this...
Code:
Sub replaceall()
'
' replaceall Macro
'

'
Dim finalcolumn As Long
Dim MyRange As Range

finalcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

Set MyRange = ActiveSheet.Range(Cells(1, finalcolumn), Cells(ActiveSheet.Rows.Count, finalcolumn))

MyRange.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,716
Members
452,939
Latest member
WCrawford

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