PDA

View Full Version : Target Column



kimbap
11-27-2012, 10:24 AM
Hi Guys,

I'm new here. Need assistance.

I need help with my current project.

Details:

1.) There is a button assigned to a macro.
2.) When the button is clicked, and the active cell or active cursor is under column A, then a pop-up message will appear "Run Macro"
3.) When the button is clicked while the active cell is not under column A (for example active cell is currently on cell B5), then a pop-up message will appear "Unable to run macro"

Please help.

Thanks.

GarysStudent
11-27-2012, 11:18 AM
Give this a try:

Sub ButtonCode()
With ActiveCell
If .Column = 1 Then
MsgBox "Run Macro"
Else
MsgBox "Unable to run macro"
End If
End With
End Sub

kimbap
11-29-2012, 07:49 AM
Thank you Gary. This is perfect!

kimbap
11-30-2012, 08:56 AM
Hi Gary… Thanks again for the help… I need another one…


Details:

1. A button is assigned to a macro
2. When the button is clicked, message box "Great" will appear when there is a word "Good" in any cell in Columns("A:A")
3. Else message box "Bad" will appear.

Million Thanks!

GarysStudent
11-30-2012, 09:04 AM
Try this:

Sub ButtonCode2()
Dim rLook As Range, r As Range
Set rLook = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For Each r In rLook
If InStr(r.Value, "Good") > 0 Then
MsgBox "Great"
Exit Sub
End If
Next
MsgBox "Bad"
End Sub

kimbap
11-30-2012, 09:32 AM
Thank you for the quick response Gary... I tried using the formula above... I type "Good" in Cell A5 and ran the formula... Message box "Great" displayed correctly... However, when I deleted the word "Good" in Cell A5 and typed "Good" in Cell C5, the formula did not run correctly ("Run Time Error..."). Any advice?

Thanks again Gary.

GarysStudent
11-30-2012, 09:38 AM
Column A can not be completely empty.