Consulting

Results 1 to 10 of 10

Thread: If I want to change the contents in the cell

  1. #1

    If I want to change the contents in the cell

    If I want to change the contents in a bunch of cells in Column E, only if those cells contain "Menu: TBA Wine:TBA." If it contains the string "Menu: TBA Wine:TBA," how do I change it to "Will receive information soon" in red text?

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Well you can do this quickly without a macro. Just select column E and press Ctrl + h to bring up the replace dialog. Then just replace one string for the other. Then you can create a conditional format to color those cells red.

  3. #3
    Quote Originally Posted by DRJ
    Well you can do this quickly without a macro. Just select column E and press Ctrl + h to bring up the replace dialog. Then just replace one string for the other. Then you can create a conditional format to color those cells red.
    Yeah, I know. I just wanted to know how to do it in code out of curiosity. Nothing pressing.

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Give this macro a try.


    Option Explicit
    
    Sub Macro1()
    Dim Cel             As Range
    Dim Str             As String
    Dim FirstAddress    As String
    Dim Rng             As Range
    Str = "Menu: TBA Wine:TBA"
        With Range("E:E")
            Set Cel = .Find(What:=Str, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
            If Not Cel Is Nothing Then
                FirstAddress = Cel.Address
                Do
                    If Rng Is Nothing Then
                        Set Rng = Cel
                    Else
                        Set Rng = Union(Rng, Cel)
                    End If
                    Set Cel = .FindNext(Cel)
                Loop While Not Cel Is Nothing And Cel.Address <> FirstAddress
                Rng.Value = "Will receive information soon"
                Rng.Font.ColorIndex = 3
            End If
        End With
    End Sub

  5. #5
    thanks a mil

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

  7. #7
    oh, one more question. If the text in the cell was a link from another spreadsheet that read "Menu: TBA Wine:TBA," and I wanted to change it, would that code work?

  8. #8
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Should work fine.

  9. #9
    yup it does.

    How long have you been using VBA? I must bow to the king (or queen)! lol!!


  10. #10
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I have been at it for several years now.

Posting Permissions

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