+ Reply to Thread
Results 1 to 6 of 6

VBA message box based on text being present

Hybrid View

  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    Bridgend, South Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    10

    VBA message box based on text being present

    Hi All,

    Regular visitor first time poster here, can someone offer help with this:

    I've got code for a message box popup for text within a cell if that is the only text in the cell, what I need is a popup box if the text within the cell contains a particular string of letters, specifically one of my customers names..

    So the customers name is "ST CROLLES", but the cell will contain other text too..just need a popup if the text "ST CROLLES" is contained within the whole text entered into any cell in column H.

    Hope I've explained what I need properly!

    Many thanks in advance guys..

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA message box based on text being present

    Something like:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim c As Range, stMatch As String
    
        stMatch = "ST CROLLES"  'change this value as necessary
    
        For Each c In Target
            If c.Column = 8 And InStr(LCase(c.Value), LCase(stMatch)) > 0 Then
                MsgBox Chr(34) & stMatch & Chr(34) & " entered in cell " & c.Address(0, 0)
            End If
        Next c
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    04-23-2013
    Location
    Bridgend, South Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA message box based on text being present

    Perfect! Many many thanks Olly! Top man!

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA message box based on text being present

    FWIW:

    Sub LewisK()
    Dim i As Long
    For i = 2 To Range("H" & Rows.Count).End(3).Row
        If Cells(i, "H") Like "*ST CROLLES*" Then
            MsgBox "Row " & i & " Column " & "H" & " has the word"
        End If
    Next i
    End sub

  5. #5
    Registered User
    Join Date
    04-23-2013
    Location
    Bridgend, South Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA message box based on text being present

    Thanks John!

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA message box based on text being present

    You're welcome. Glad to help out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 10-20-2014, 01:13 PM
  2. [SOLVED] Change cell colour based on text being present - conditional formatting?
    By rob-the-randy-rascal in forum Excel General
    Replies: 8
    Last Post: 08-01-2013, 11:24 AM
  3. [SOLVED] Auto Hiding rows based on range/data present or not present.
    By raze in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 02-10-2013, 11:27 AM
  4. [SOLVED] Macro to sum based on certain text being present, range changes at variable rows
    By mistye525 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-26-2012, 08:02 PM
  5. [SOLVED] Merge/unmerge based on whether specific text is present in a column
    By susanbarbour in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2012, 09:08 AM

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