Help with Find and Replace numbers with autofilter on selected column

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, I am trying to replace certain numbers with numbers in a selected column that has been filtered on a specific number in that column but can't get my head around it. but I need to be able to filter on the column selected. Also I am having trouble with the number changing visually when a 0 is at the start This is what I have so far.

Code:
Dim rngAddress As Range
  Set rngAddress = Range("G1:H1").Find("Foot")
  If rngAddress Is Nothing Then
    Exit Sub
  End If
  Range(rngAddress, rngAddress.End(xlDown)).Select
    Selection.NumberFormat = "@"

'''Filter on number 603 using the selected column'''

    Selection.Replace What:="603", Replacement:="0603", LookAt:=xlPart, SearchOrder:=xlByRows

''' Filter off '''

Can someone help with this please.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
This is what I am trying to filter and replace on but only if found

Code:
    Selection.AutoFilter
    ActiveSheet.Range("Column G or H to the end of filtered data?").AutoFilter Field:=1, Criteria1:="201"
    Selection.Replace What:="201", Replacement:="0201", LookAt:=xlPart, SearchOrder:=xlByRows
    Selection.AutoFilter

    Selection.AutoFilter
    ActiveSheet.Range("Column G or H to the end of filtered data?").AutoFilter Field:=1, Criteria1:="402"
     Selection.Replace What:="402", Replacement:="0402", LookAt:=xlPart, SearchOrder:=xlByRows
    Selection.AutoFilter

    Selection.AutoFilter
    ActiveSheet.Range("Column G or H to the end of filtered data?").AutoFilter Field:=1, Criteria1:="603"
     Selection.Replace What:="603", Replacement:="0603", LookAt:=xlPart, SearchOrder:=xlByRows
     Selection.AutoFilter

    Selection.AutoFilter
    ActiveSheet.Range("Column G or H to the end of filtered data?").AutoFilter Field:=1, Criteria1:="805"
     Selection.Replace What:="805", Replacement:="0805", LookAt:=xlPart, SearchOrder:=xlByRows
     Selection.AutoFilter
 
Last edited:
Upvote 0
You don't need to filter to replace. Just use xlWhole instead of xlPart. Your columns need to be formatted as text before you do the replace.
 
Upvote 0
I know I don't need to but I might get other data in the column which might contain these numbers in a longer string, all i have to do is add match case set to true in the code The first bit of code above shows I am formatting it into text before replacing. The issue is that the 0 I want in front of the numbers is not showing up and is staying as if the format is in general i.e. 201,402,603,0805.
 
Upvote 0
Do you want to add zeroes to just specific values or all numbers? This may help?

Code:
lr = Application.Max(Range("G" & Rows.Count).End(xlUp).Row, Range("H" & Rows.Count).End(xlUp).Row)
Set Rng = Range("G1:H" & lr)
Rng.NumberFormat = "@"
For Each c In Rng.Cells
    Select Case c.Value
        Case 201: c.Value = "0201"
        Case 402: c.Value = "0402"
        Case 603: c.Value = "0603"
        Case 805: c.Value = "0805"
    End Select
Next
 
Upvote 0
It is just specific values that I stated above. the code works great, had to turn off the numbers stored as text error settings, Thanks for your help it's much appreciated.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

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