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
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,197
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
 

Fepsch

New Member
Joined
Jan 6, 2012
Messages
5
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!
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,197
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.
 

Fepsch

New Member
Joined
Jan 6, 2012
Messages
5
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?
 

Forum statistics

Threads
1,081,695
Messages
5,360,679
Members
400,592
Latest member
katekoz

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top