if-then program hangs
if-then program hangs
(OP)
Hi..
I'm trying to write a simple vba for my excel spreadsheets. I'm wondering why this will cause my spreadsheet to hang when I input a value of 1 on B2.
I'm a structural engineer and novice on vba. I appreciate for your help.
Here's the code:
Sub Worksheet_Change(ByVal Target As Range)
If Range("a1").Value = 1 Then
Range("B1").Value = "-"
End If
If Range("a2").Value = 1 Then
Range("B2").Value = "-"
End If
End Sub
Thanks,
Noel
I'm trying to write a simple vba for my excel spreadsheets. I'm wondering why this will cause my spreadsheet to hang when I input a value of 1 on B2.
I'm a structural engineer and novice on vba. I appreciate for your help.
Here's the code:
Sub Worksheet_Change(ByVal Target As Range)
If Range("a1").Value = 1 Then
Range("B1").Value = "-"
End If
If Range("a2").Value = 1 Then
Range("B2").Value = "-"
End If
End Sub
Thanks,
Noel





RE: if-then program hangs
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: if-then program hangs
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: if-then program hangs
CODE
If Target.Address = "$A$1" And Range("a1").Value = 1 Then
Range("B1").Value = "-"
End If
If Target.Address = "$A$2" And Range("a2").Value = 1 Then
Range("B2").Value = "-"
End If
End Sub
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: if-then program hangs
Also you can accomplish same thing without vba using if formula in the b1 and b2 cells which check the value of a1 and a2 and adjust their output .
Of course if you're just tryign to learn vba I understand why you might want to use vba instead for the educational value.
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: if-then program hangs
This solves my problem. Actually, I gonna tweak this a little bit and add this to my spreadsheet about lateral loads. Yeah, this conditions can be done without vba but what I'm really planning to do is to lock or unlock cells with a value of a cell equals to a certain value. I'm hoping this code will be a good way to start with additional "else" condition and adding something like Range("B2").Locked=true.
Thanks again guys. Hope I can still ask your help as problems come along the way.
RE: if-then program hangs
CODE
Private Sub Worksheet_Change(ByVal Target As Range)
If (bProcessing) Then Exit Sub
bProcessing = True
If Range("A1").Value = 1 Then
Range("B1").Value = "-"
End If
If Range("A2").Value = 1 Then
Range("B2").Value = "-"
End If
bProcessing = False
End Sub