Help with basic IF statement

alexbat

New Member
Joined
Dec 12, 2013
Messages
32
Hi,

trying to write a script to be performed in Sheet 1 if calculated value in Sheet 3 is changed.
I put this piece of code in sheet 3 just a test to see if I understand how to make an if statement:

Code:
Private Sub Worksheet_Calculate()
   
    Sheet1.Select
    
    If Range("O1").Value = "11" Then
       
    Range("O2").Select
    ActiveCell.FormulaR1C1 = "Code works"
        
    End If
  
    
End Sub

Unfortunately, it does not work. Any suggestions on what I´m doing wrong. Tried both with and without the "" for the value 11.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
alexbat,

Not sure if you are really wanting to select sheet1 or if you have used select because you think that it is necessary in order to get "code works" into sheet1?

Try this.....

Code:
Private Sub Worksheet_Calculate()    
If Sheets("Sheet1").Range("O1") = 11 Then Sheets("Sheet1").Range("O2") = "Code Works"
Sheets("Sheet1").Select
End Sub

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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