Multiple If Statement actions

davonovic

New Member
Joined
Mar 28, 2013
Messages
5
Hi, I'm trying to get more than one cell to display a text string but it ends up getting caught into an infinite loop i think. I don't know how else to write this. Any suggestions/alternate methods are greatly appreciated.

Private Sub worksheet_change(ByVal target As Range)
Dim cell As Range

For Each cell In Range
With cell
If Cells(.Row, "C") > 0 Then
Cells(.Row, "B") = Int(Now)
Cells(.Row, "A") = "Completed"
Else
Cells(.Row, "B") = Null
End If
End With
Next cell
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I see several problems here. First, you never define what "Range" should be checked. You must tell the macro what range of cells you want to check (see Set statement below). Next, every time you change a cell inside the If statement, Excel will launch the Worksheet_Change event, because the worksheet is changing (makes sense right?). Disabling and enabling events will solve that problem. Lastly, learn to indent your code (makes debugging problems easier). The following code should do what you need.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim MyRange As Range
Set MyRange = Range("C1:C10")
For Each cell In MyRange
With cell
If Cells(.Row, "C") > 0 Then
Application.EnableEvents = False
Cells(.Row, "B") = Int(Now)
Cells(.Row, "A") = "Completed"
Application.EnableEvents = True
Else
Application.EnableEvents = False
Cells(.Row, "B") = Null
Application.EnableEvents = True
End If
End With
Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,196,329
Messages
6,014,678
Members
441,835
Latest member
rthomas268

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