+ Reply to Thread
Results 1 to 3 of 3

Find/Replace Cell Values with Named Ranges

Hybrid View

  1. #1
    Registered User
    Join Date
    02-10-2010
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    2

    Find/Replace Cell Values with Named Ranges

    Hi,

    I have a number of named ranges that I need to find/replace data in.

    For example, in range "PAPKGC" there are three variables: F, P, and X. For "F", the cell needs to contain the word "Flat". "P" is to contain "Package" and "X" is to be blank. Range "PASIDE" also contains 2 variables. I am to concatenate any cells with a value of 2 with "/pk" and any cells with a value of 1 are to be blank.

    So my big question is: How can I use the named ranges to find and replace this data using a VBA macro?

    This is what I'm trying, but I have no idea what I'm doing.
    Sub ReplaceText()
        Dim rngData As Range, rngCell As Range
             
        With ThisWorkbook
            Set rngData = Range("PAPKGC")
        End With
         'define the data range to evaluate
         
        For Each rngCell In rngData
            Select Case rngCell.Value
                Case "F"
                    cell.Value = "Flat"
                Case "P"
                    cell.Value = "Package"
            End Select
        Next rngCell
    End Sub
    Any help is appreciated!

    -G
    Last edited by Leith Ross; 02-10-2010 at 05:32 PM. Reason: Added Code Tags

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro Help: Find/Replace Cell Values with Named Ranges

    Do you mean that if a cell has 'F' in it you want to replace it with 'Flat'? If so, why not just use Find and Replace from the worksheet?

  3. #3
    Registered User
    Join Date
    03-08-2007
    Posts
    93

    Re: Macro Help: Find/Replace Cell Values with Named Ranges

    Try something like this:

    Sub ReplaceText()
    With Range("MyRange")
        .Replace What:="F", Replacement:="Flat"
        .Replace What:="P", Replacement:="Package"
    End With
    End Sub
    Hope this helps

    SAE

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1