Consulting

Results 1 to 4 of 4

Thread: Find "PR" in column O then color cell and msgbox

  1. #1
    VBAX Regular
    Joined
    Nov 2011
    Posts
    23
    Location

    Find "PR" in column O then color cell and msgbox

    Hello All,

    I am in need of Private Sub code that will do three things...

    1. Detect "PR" in column O (15)

    If in column O "PR" is pasted then ...

    a. Msgbox ("Alert")
    b. Color the cell - Interior.ColorIndex = 46 'Orange



    2. Capitalizes the first letter of words in columns J - N

    3. Make the email address in column T to be all lower case


    Thank you in advance

  2. #2
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    dim c as long
      'scan the col A
    range("A2").select
    While ActiveCell.Value <> ""
          'set col T
       ActiveCell.offset(0,19).Value = LCase(ActiveCell.offset(0,19).Value)
          'COL O
       IF ActiveCell.offset(0,14).Value = "OP" THEN  
             ActiveCell.offset(0,14).Interior.ColorIndex = 46  'Orange
            ' MSGBOX "ALERT"
      END IF
    
        for c = 9 to 13   'j thru n set proper case
           ActiveCell.offset(0,c).Value = Application.WorksheetFunction.Proper(ActiveCell.offset(0,c).Value)
        next
    
       ActiveCell.Offset(1, 0).Select  'next row
    Wend

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Sub find_color_alert()
        
        Dim fCell As Range
        Dim j As Long
        Dim msg As String, fAddress As String
        
        msg = "PR found in cells:" & vbLf
        
        With ActiveSheet
            Set fCell = .Columns(15).Find("PR", , , xlWhole) 'full match
            'Set fCell = .Columns(15).Find("PR", , , xlPart) 'partial match
            If Not fCell Is Nothing Then
                fAddress = fCell.Address
                Do
                    fCell.Interior.ColorIndex = 46
                    For j = 10 To 14 'col J thru col N
                        .Cells(fCell.Row, j).Value = Application.Proper(.Cells(fCell.Row, j).Value)
                    Next
                    .Cells(fCell.Row, 20).Value = LCase(.Cells(fCell.Row, 20).Value)
                    msg = msg & fCell.Address(0, 0) & vbLf
                    Set fCell = .Columns(15).FindNext(fCell)
                Loop While Not fCell Is Nothing And fCell.Address <> fAddress
                MsgBox msg
            End If
        End With
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Regular
    Joined
    Nov 2011
    Posts
    23
    Location
    Thanks everyone. They both work.

Posting Permissions

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