OzGrid

How to use VBA code to select if cell contains any text return text in another cell

< Back to Search results

 Category: [Excel]  Demo Available 

How to use VBA code to select if cell contains any text return text in another cell

 

Requirement:

 

The user is currently working on a project and needs the words "In Progress" to appear in one cell, when a customer's name appears in another cell, in a different column. The user is using VBA and have tried many different formulas, but none of them work when the user plugs in a customer's name.

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/1202117-if-cell-contains-any-text-return-text-in-another-cell

 

Solution:

 

Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your "In-Progress" sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter a value in column A and exit the cell.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    If Target <> "" Then
        Range("E" & Target.Row) = "In Progress"
    Else
        Range("E" & Target.Row) = ""
    End If
End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by Mumps.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to calculate userform textbox and cell value for label caption
How to create a macro to round total based on a cell value
How to find/return first nonblank value in adjacent cell from column with duplicate values
How to use VBA code to print number of copies based on cell value

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)