Check clicked cell is in right column

Fepsch

New Member
Joined
Jan 6, 2012
Messages
5
Hey guys...

I want to check if the cell clicked is in the right column... and if not, then exit sub...

This is the code:

Dim lNum As Long


On Error Resume Next

Application.DisplayAlerts = False

lNum = Application.InputBox _
(Prompt:="Ingrese la Factura que desea pagar.", _
Title:="PAGO DE FACTURAS", Type:=1)

On Error GoTo 0

Application.DisplayAlerts = True

If Intersect(ActiveCell, Range("Q:Q")) Is Nothing Or lNum = 0 Then
MsgBox "You did something wrong. Remember you have to click the Invoice Number"

Exit Sub


Else ...

Please give me a hand...

Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Not sure exactly what you are asking, but if you want to make sure that the active cell is in column Q, or else abort the macro, you can start the macro with this line:

If activecell.Column <> 17 then exit sub

or more user friendly

If activecell.Column <> 17 then
MsgBox "Please select a cell in column Q.", 64, "Cannot continue."
exit sub
end if
 
Upvote 0
Yeap, that is what i want to do...
But once they clicked the cell, how can i pick up INum column to check if it is different to 17?

I tried
If Range("lNum").Column <> 17 Then ...

But didnt work

Thank for your help!
 
Upvote 0
I don't understand why you are concerned with that. If the active cell is not in column Q then the macro does not proceed.

If the active cell is in column Q, the inputbox appears and the user can select a range of cells. It is not evident in your abbreviated posted code what is supposed to happen to that selected range.
 
Upvote 0
Actually the macro goes further to the next step if the user clicks on the column 18 as well, because both are Type=1... both numbers. But it wont work, and an error comes up.

What this macro is doing is introducing old payments when paid by clients... so each time somebody pays me an owed invoice, I have to click on a Pivot Table the Invoice Number (column 17) I want to pay.
In column number 17 goes the invoice number. And in column 18 goes the amount of money of that invoice.

If by mistake you click on the column 18, the macro begins seeking a wrong number and will loop forever.

Did my explanation help?
 
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

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