DavidSchilp
New Member
- Joined
- Jan 27, 2024
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
I'm trying to write a macro that uses a condition to check cells and then go down one or two cells and then check again. It will keep doing this until an end condition is met.
I tried uploading the add-in but Excel tells me I can't because I'm using Protected Viewing. That may be because this version is through a university.
I think I'm close. Putting in the EndIf let it run until it tells me that It doesn't see a Loop Command. It's there, but somethings off.
Any help appreciated. I've used Excel since it came out in 1986. But don't do macros much. I'm sure it's not as pretty as it could be.
I'm not sure at what stage the Dim statements should be.
I tried uploading the add-in but Excel tells me I can't because I'm using Protected Viewing. That may be because this version is through a university.
I think I'm close. Putting in the EndIf let it run until it tells me that It doesn't see a Loop Command. It's there, but somethings off.
Any help appreciated. I've used Excel since it came out in 1986. But don't do macros much. I'm sure it's not as pretty as it could be.
I'm not sure at what stage the Dim statements should be.
VBA Code:
Sub Checker()
If Range("N7").Value < 0 And Range("H7").Value > 0 Then 'Initial results that need to be met to bother running this
Dim x As Integer: x = 2
Dim e As Integer: e = 0
Do While x < 35 And Range("N7").Offset(x).Value < 0
If Range("H7").Offset(x).Value < 0 Then
x = x + 2 'skip next line down in sheet
ElseIf Range("K7").Value < Range("K7").Offset(x).Value And Range("L7").Value > Range("L7").Offset(x).Value Then
Range("P7").Value = "Buy" And Range("J7").Offset(x).Value = Range("Q7").Value _
And e = 1 'post results in cells
ElseIf x > 35 Or Range("N7").Offset(x).Value > 0 Then
e = 1 'Out of range so stop
ElseIf e = 1 Then Exit Sub 'Done with this process
Else: x = x + 1 'Go to next line down
End If
Loop
Else: Exit Sub
End Sub
Last edited by a moderator: