Module Counter

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,059
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have module and sub name as Sub MonthlyOldDataRemove this is all perfect.
I have another module and sub name as sub sundaycall


sunday script goes as, it will only run it the syst,e day is sunday.
VBA Code:
Sub sundaycall()
If Sheets("Weekly YoDate-RawData").Range("B1").Value <> "Sunday" Then
    Exit Sub
End If

rest of the code is all pefect. only on sunday the Sub MonthlyOldDataRemove is run 3 times, but is ther a way when on sunday this Sub MonthlyOldDataRemove runs on the 3 time it will executive sub sundaycall first 2 times it will not run sub sundaycall only 3time it will run sub sundaycall.
I did tried to put a counter as if the Sub MonthlyOldDataRemove is more than 2 only on sunday then it should run the sub sundaycall, but its failing.

any suggestions.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You could store the count in a cell somewhere in your workbook called SundayCount, starting with the value 0.

Then ...

VBA Code:
Sub MonthlyOldDataRemove()

    'Remove data
            
    If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then
        With Range("SundayCount")
            .Value = .Value + 1
            If .Value = 3 Then
                .Value = 0
                Call sundaycall
            End If
        End With
    End If

End Sub
 
Upvote 0
You could store the count in a cell somewhere in your workbook called SundayCount, starting with the value 0.

Then ...

VBA Code:
Sub MonthlyOldDataRemove()

    'Remove data
           
    If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then
        With Range("SundayCount")
            .Value = .Value + 1
            If .Value = 3 Then
                .Value = 0
                Call sundaycall
            End If
        End With
    End If

End Sub
ok sure will give it a try on this sunday

i have give c3 cell name as "SundayCount" in same sheet "Weekly YoDate-RawData"
Thank you for your support and help

the modifited code looks like, in case i have to do any changes please let me know.


VBA Code:
Sub sundaycall()
If Sheets("Weekly YoDate-RawData").Range("B1").Value <> "Sunday" Then
    Exit Sub
End If

'Modifited Code
If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then
        With Range("SundayCount") 'cell c3
            .Value = .Value + 1
            If .Value = 3 Then
                .Value = 0
                Call sundaycall
            End If
        End With
    
'End If

'If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then

''''''''''''
'To check system day is Sunday
'and remove old monthly data
''''''''''''
Call QtyOldDataRemoveQandY
Call MonthlyOldDataRemoveQandY

End if
End Sub
 
Upvote 0
Hi

StephenCrump

I tried this today been Sunday, but script is not working as disered,
it just check sunday and not the counter and execute the call sunday.
VBA Code:
Sub sundaycall()

If Sheets("Weekly YoDate-RawData").Range("B1").Value <> "Sunday" Then

    Exit Sub
  
End If



If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then
        With Range("C3")
            .Value = .Value + 1
            If .Value = 3 Then
                .Value = 0
                Call sundaycall
            End If
       End With
    
'End If

'If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then

''''''''''''
'To check system day is Sunday
'and remove old monthly data
''''''''''''
Call QtyOldDataRemoveQandY
Call MonthlyOldDataRemoveQandY
End If
End sub
 
Upvote 0
VBA Code:
Sub sundaycall()


If Not Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then

    Exit Sub
  
End If



If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then
    Select Case Range("C3").Value
        Case Is < 3
            Range("C3").Value = Range("C3").Value + 1
        Case Is = 3
            Range("C3").Value = 0
            Call QtyOldDataRemoveQandY
            Call MonthlyOldDataRemoveQandY
    End Select
End If
    
'End If

'If Sheets("Weekly YoDate-RawData").Range("B1").Value = "Sunday" Then

''''''''''''
'To check system day is Sunday
'and remove old monthly data
''''''''''''


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,005
Members
449,092
Latest member
masterms

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