Find and Replace troubles

jmazorra

Well-known Member
Joined
Mar 19, 2011
Messages
715
Hello folks;

The code below sorts my sheets by column A and then searches in column A for value 0 and changes to Unassigned. The code works, however, I just want to replace cells that only have a 0 value not those that contain 0 within the string of values. For example:

Column A before code

Maintenance
Accounting
401k
Benefits
0

Should end up after code

401k
Accounting
Benefits
Maintenance
Unassigned.

Right now it changes my 401k to 4UnassignedK

My code is as follows

Code:
Sub sort_Remove_Dup_CSM_Rep()

'This is Step 4 when the frmDataImportSplash is activated.
'This procedure sorts and removes all duplicates in the repname and csmname.
'This is used to manage the employee, csm list in the dasboard.
'If there is not team assigned to the account,
'go ahead and replace the empty cell with the word Unassigned

Application.ScreenUpdating = False

For Each WS In Sheets(Array("repName", "csmName", "benRepName", "departmentName"))

    WS.Sort.SortFields.Clear

    WS.Sort.SortFields.Add Key:=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

  [COLOR=#b22222]  WS.Columns("A:A").Replace What:="0", Replacement:="(Unassigned)", _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False[/COLOR]
[COLOR=#b22222]With WS.Sort
[/COLOR]    
         .SetRange Range("A:E")
         .Header = xlNo
         .MatchCase = False
         .Orientation = xlTopToBottom
         .SortMethod = xlPinYin
         .Apply
    
        End With
  
    WS.Range("A:C").RemoveDuplicates Columns:=1, Header:=xlNo
    
           Next WS
      
                               
          Application.ScreenUpdating = True

End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try changing this:
Code:
LookAt:=xlPart
To this:
Code:
LookAt:=xlWhole
 
Upvote 0

Forum statistics

Threads
1,206,830
Messages
6,075,113
Members
446,123
Latest member
junkyardforme

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