If column contains specific texts, run a specific macro

peltron

New Member
Joined
Jul 13, 2016
Messages
20
Hi everyone,

I'm new here and pretty much a noob with VBA, and am having some trouble which I really hope some kind souls can help me with! :confused:

The problem that I have right now at work is unable to be recorded, and hence I would like to seek some help.

For example, each time a user refreshes a workbook, column B may contain a range of 13 alphabets from "A" to "M".
If in column B,
"A" is present, run code A.
"B" is present, run code B.

and etc.


Thank you for your time and understanding!!!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Let's talk a little bit.

What does "Refresh" mean?
Your quote:
"For example, each time a user refreshes a workbook"

Do you mean when you open the workbook.
And if so what sheet are we dealing with.

And when you say:
"A" is present, run code A.

Do you mean Run the macro named "A"
 
Upvote 0
Hi,

There is a button which users press to refresh the data set, hence changing the data in column B too.

If the text "A" is present in any cells in column B, run the macro named "A".

I hope this provides more clarification!
 
Upvote 0
Show me the script in the button you press to do the refresh.

And then I can add some additional scripting to that button.
 
Upvote 0
Hi,

Below is the code assigned to the refresh button. It does some sorting of data beforehand.

Thank you.


Sub AC()


Sheets("Data").Select
On Error Resume Next
Range("E1:E100000").Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete



Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long


fndList = Array("Australia", "CHINA", "HONG KONG", "Indonesia Distrib.", "JAPAN", "KOREA", "MyanmarCambodiaLaos", "Malaysia", "New Zealand", "PHILIPPINES", "SINGAPORE", "TAIWAN", "THAILAND", "VIETNAM")
rplcList = Array("AUS", "CHN", "HKG", "IDN", "JPN", "KOR", "MCL", "MYS", "NZL", "PHL", "SGP", "TWN", "THA", "VNM")


'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht

Next x


ActiveWorkbook.RefreshAll


Sheets("Target Classes").Select
ActiveWorkbook.Worksheets("Target Classes").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Target Classes").AutoFilter.Sort.SortFields.Add Key _
:=Range("R1:R10000"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Target Classes").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
 
Upvote 0
I'm not sure how to do what you want. Maybe someone else here at Mr. Excel will have an answer.
 
Upvote 0
You need a script like this.
But I'm not sure where you should put it.

Code:
Sub Called_MyScripts()
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        ans = Cells(i, 1).Text
        Application.Run ans
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,037
Messages
6,128,442
Members
449,453
Latest member
jayeshw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top