excelbytes
Active Member
- Joined
- Dec 11, 2014
- Messages
- 291
- Office Version
- 365
- Platform
- Windows
I have three codes that are virtually the same, Activity 1, 2 & 3. The only difference is the offset function that goes from 9, to 10, to 11 after the qStart row of code.
The process goes that I activate an action and it populates columns A through E as shown on the example. What the code for the activities that is shown below, is that it will enter a "1" in either L, M or N for the current row. The code is supposed to find the last entry in column C, go over based on the offset and enter the "1". It runs fine when I step through the code (F8), but not when I activate the macro. As you can see by the image attached, it just puts the 1 in the first row. Any thoughts?
Here is my code:
The process goes that I activate an action and it populates columns A through E as shown on the example. What the code for the activities that is shown below, is that it will enter a "1" in either L, M or N for the current row. The code is supposed to find the last entry in column C, go over based on the offset and enter the "1". It runs fine when I step through the code (F8), but not when I activate the macro. As you can see by the image attached, it just puts the 1 in the first row. Any thoughts?
Here is my code:
VBA Code:
Sub Activity1()
'
' Enter 1 for Activity #1
Dim rStart As Range, pStart As Range, qStart As Range
Application.ScreenUpdating = False
With Sheets("Activities")
Set rStart = .Columns("C").Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious).Offset(0, 0)
If Application.Sum(rStart.Resize(, 2).Value) = 0 Then
Application.Goto Sheet1.Range("A1")
MsgBox "Select Type first"
Else
Set pStart = .Columns("C").Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious).Offset(0, 9)
If Application.Sum(pStart.Resize(, 20).Value) > 0 Then
Application.Goto Sheet1.Range("A1")
MsgBox "You already selected an Activity"
Else
If Application.Sum(Range("E2:H2")) = 0 Then
.Range("B2").Offset(0, 10).Value = 1
Else
Set qStart = .Columns("C").Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious).Offset(, 9)
qStart.Value = 1
End If
End If
End If
End With
With Application
.Goto Sheets("DASHBOARD").Range("A1")
.ScreenUpdating = True
End With
End Sub