Simple If statement

drewbsking

New Member
Joined
Nov 3, 2011
Messages
34
Can anyone please tell me why the heck this does not work?

Code:
If ActiveCell.Column <> 51 Or ActiveCell.Column <> 52 Then
MsgBox "You can not edit this column.", vbCritical, "For your safety..."
Else
CODEact
End If

Thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You haven't said why this doesn't work, but since the activecell cannot be in column 51 AND 52, I would expect your If statment to always return false.

Try changing the OR to AND.
 
Upvote 0
Code:
Private Sub SpinButton1_SpinDown()
If ActiveCell.Column <> 51 And ActiveCell.Column <> 52 Then
MsgBox "You can not edit this column.(AY or AZ only please.)", vbCritical, "For your safety..."
Else
'Check user input!
  Dim Cell As Range
  On Error Resume Next
  For Each Cell In Selection
    If Len(Cell.Value) Then Cell.Value = Cell.Value - Me.ManualNum.Value
  Next
      
End If
      End Sub

This is to use a spin button the change a cell value by a value that is listed in manualnum text box.

The AND works. That was an easy one for this morning. Thanks for your help! I never considered AND because I dont need both conditions to be true. I just wanted to prevent a macro from running in any other column except 51 ("AY") and 52 ("Az"). The OR would prevent the macro from running at all.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,128,027
Members
449,414
Latest member
sameri

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