2

I'm trying my hand at VBA.

I have a statement that says:

Sub PM()

Set rn = ActiveWindow.VisibleRange.Cells(1, 1)
Application.ScreenUpdating = False
'If Not Intersect(Target, Range("C27")) Is Nothing Then
If Range("C27") = 3 Then
ActiveSheet.Shapes("Option Button 28").Select
Selection.Enabled = False
If Range("J57") < 455 Then
Range("J56") = False
Else
Range("J56") = True
End If
Else
ActiveSheet.Shapes("Option Button 28").Select
Selection.Enabled = True
End If
rn.Activate
Application.ScreenUpdating = True

End Sub

When I change cell C27, the value passed to cell J56 works perfectly. But once the value in C27 is chosen, and I then change cell J57, J56 doesn't change accordingly as it should. I have to change C27 value again to trigger J56 to reflect the right value.

Can anyone point out what I'm doing wrong?

  • 1
    Where are the end ifs?. Are you reliant on C27 being a 3 in order to evaluate J57 – Dave Feb 24 '16 at 19:48
  • 1
    @dave: endifs are not required in the case of a single statement followin the condition – Yorik Feb 24 '16 at 19:50
  • 2
    @yorik I am aware of that but OP stated nested ifs meaning there has to be "end if", or else they are not nested are they! – Dave Feb 24 '16 at 19:51
  • So I have added the rest, but I think I see that I only have 1 End If. This is probably my issue? – user1551817 Feb 24 '16 at 19:52
  • 2
    What is this? worksheet_change? And your second if only fires if the first if is true – Raystafarian Feb 24 '16 at 19:53
2

I am guessing wildly here, but I expect that you are calling this code from an Event fired on c27 only, so if you edit j57, the function/sub is not called.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.