Assigning a hotkey to run only from a given range

A

Andyjim

We need to ensure that a hot key will only activate from a given range (in
this case any cell in Column B). The code below shows 2 attempts (1 attempt
is commented out). Any help on this would be greatly appreciated!

ActiveCell.Select
If ActiveCell = "controlPrange" Then
'If Selection.Locked = True Then
'Exit Sub
ActiveCell.Offset(rowoffset:=0, columnoffset:=37).Activate
Selection.Copy
ActiveCell.Offset(rowoffset:=0, columnoffset:=-26).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

'Copy from Optimum Position Size Formula cell to Optimum Position Size cell
ActiveCell.Offset(rowoffset:=0, columnoffset:=27).Activate
Selection.Copy
ActiveCell.Offset(rowoffset:=0, columnoffset:=-29).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveCell.Offset(rowoffset:=0, columnoffset:=-9).Activate
Else
Exit Sub
End If
 
O

Otto Moehrbach

Not sure what you want. I'll assume that you want your code to run only if
the active cell is in Column B. Something like this might work for you.
HTH Otto
Sub DoIt
If Not Intersect(ActiveCell, Columns("B:B")) Is Nothing Then
'Your code here
End If
End Sub
 
A

Andyjim

Perfect! Thanks so much Otto!

Otto Moehrbach said:
Not sure what you want. I'll assume that you want your code to run only if
the active cell is in Column B. Something like this might work for you.
HTH Otto
Sub DoIt
If Not Intersect(ActiveCell, Columns("B:B")) Is Nothing Then
'Your code here
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top