Formatting problem - no longer works

peterhw

New Member
Joined
Jan 23, 2012
Messages
39
VBA Code:
    Sheets("Print_Results").Range(myrange).Replace What:="£", Replacement:=""  '   , SearchOrder:=xlByColumns, MatchCase:=True
    Sheets("Print_Results").Range(myrange).Replace What:="$", Replacement:=""  '   , SearchOrder:=xlByColumns, MatchCase:=True

I have been using the above for ages (years) to enable me to take the contents of a listbox and print to a worksheet but to remove any 'hard' currency symbols before formatting that then allows me to see formatted numbers but without the 'hard' symbol. (they still appear as numbers rather than alpha strings with numbers, symbols, - sign etc). Each of the cells is displayed with top left hand corner containing the 'Green Triangle'

Earlier today it just failed to work and I can not see any obvious reasons. The Worksheet is correct the range is 'large'.
I get round the problem by replacing - i.e. REPLACE(xxxx,"£","") which does work
I have exited Excel and reloaded

Suspect I have done something, somewhere but just eludes me at the moment, (using Excel / Office 2016)
Anything suggestions appreciated
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try changing currency values in What:= with character codes like Chr(63) (for pounds) nad Chr(36) for dollars
VBA Code:
What:=Chr(63)
 
Upvote 0
You need to specify 'LookAt'
VBA Code:
Sheets("Print_Results").Range(myrange).Replace What:="£", Replacement:="", LookAt:=xlPart
 
Upvote 0
Really weird....
First I tried above using Chr(63) as per code below (without LOOAT line and lines UNCOMMENTED with BREAK at Range(myrange).select (to start reformatting).
Then all the date in the range got deleted - the listbox (with the source) was fine and all the data was printed to the Print Results sheet.
myrange contains A6:J5000 and rows 6 onwards vanished.
I then tried second suggestion including LookAt and all appeared to work fine.
Many thanks for both suggestions but just no idea what happened - I have been using this code for several years (without LookAt)
If I uncover any more I will post

VBA Code:
    myrange = "A" + t1 + ":J" + t2
    'Chr(63) (for pounds) nad Chr(36) for dollars
'    Sheets("Print_Results").Range(myrange).Replace What:=Chr(63), Replacement:=""  '   , SearchOrder:=xlByColumns, MatchCase:=True
'    Sheets("Print_Results").Range(myrange).Replace What:=Chr(36), Replacement:=""  '   , SearchOrder:=xlByColumns, MatchCase:=True
    'Sheets("Print_Results").Range(myrange).Replace What:="%", Replacement:=""  '   , SearchOrder:=xlByColumns, MatchCase:=True
    Sheets("Print_Results").Range(myrange).Replace What:="£", Replacement:="", LookAt:=xlPart
    Range(myrange).Select
    With Selection

Thanks again for swift responses
 
Upvote 0
Many thanks for both suggestions ...
Your welcome. :)

... but just no idea what happened
With Find/Replace of course there is that setting about whether to match the whole cell or just look at any part within the cell. Find/Replace remembers that setting from the previous time so before your code failed, at some point you have done a Find or Find/Replace (either manually or by code) where you used the setting 'Match entire cell contents' (manual) or LookAt:=xlWhole (code) and therefore that was the remembered setting.

Have a look here, especially the 'Remarks' section and remember to always specify those settings that get remembered if they are relevant to your current goal.
 
Upvote 0
Your welcome. :)

With Find/Replace of course there is that setting about whether to match the whole cell or just look at any part within the cell. Find/Replace remembers that setting from the previous time so before your code failed, at some point you have done a Find or Find/Replace (either manually or by code) where you used the setting 'Match entire cell contents' (manual) or LookAt:=xlWhole (code) and therefore that was the remembered setting.

Have a look here, especially the 'Remarks' section and remember to always specify those settings that get remembered if they are relevant to your current goal.
Many thanks. Will now headover and take a look at your suggested link.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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