Code Running On Step Through But Not When I Run The Macro

excelbytes

Active Member
Joined
Dec 11, 2014
Messages
291
Office Version
  1. 365
Platform
  1. 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:

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
 

Attachments

  • Won't Run.png
    Won't Run.png
    10.8 KB · Views: 10

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Is this part of your code meant to be looking at row, or the last used row in col C?
VBA Code:
   If Application.Sum(Range("E2:H2")) = 0 Then
      .Range("B2").Offset(0, 10).Value = 1
   Else
You are also missing the period infront of Range inside the Sum
 
Upvote 0
The missing period in front of the Range was the problem! Now it works properly! Thanks so much!
 

Attachments

  • Won't Run.png
    Won't Run.png
    15.7 KB · Views: 24
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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