Requirement:
The user wants to add one Macro to check text value from Column A (which has short text) and if add full text in Column M.
Example: A2 has "ON" and then in M2 should give "Ontario"
Formula:
=IF(
ISNUMBER(SEARCH("ON",A2)),"Ontario",
IF(ISNUMBER(SEARCH("BC",A2)),"British Columbia",
IF(ISNUMBER(SEARCH("QC",A2)),"Qubec"))
Solution:
Option Explicit Sub Province() Dim lr As Long, i As Long lr = Range("A" & Rows.Count).End(xlUp).Row For i = 2 To lr If Range("A" & i) = "ON" Then Range("M" & i) = "Ontario" ElseIf Range("A" & i) = "BC" Then Range("M" & i) = "British Columbia" ElseIf Range("A" & i) = "QC" Then Range("M" & i) = "Quebec" End If Next i End Sub
Obtained from the OzGrid Help Forum.
Solution provided by AlanSidman.
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 use VBA code to select if cell contains any text return text in another cell |
How to display a message for each if the value is greater than the mentioned values |
How to remove text after last comma, only if cell has 3 commas |
How to delete rows if cell doesn't contain criteria |
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.