Want Macro to continue after a first action

SanjayGMusafir

Well-known Member
Joined
Sep 7, 2018
Messages
1,513
Office Version
  1. 2024
Platform
  1. Windows
Hi Experts
Need some urgent help

I'm working on a macro where I want macro to go to a particular date and then perform another function. So I picked coding from my previous macros and compiling a new one...

But the problem is - My earlier Macro Says "EXIT SUB" after it finds a particular date, while I want it to continue working for the next action I want it to take. If I remove command "Exit Sub" then it keeps from from one cell to another that fulfil the condition(s).

So how to modify this macro so that it continues working after selecting a desired cell.

The part of code is as below -
Rich (BB code):
For Each cell In ActiveSheet.Range("SBISGM[Date]")
If cell.Value >= [Today()] And cell.Value < [Today()+15] Then
cell.Select
ActiveWorkbook.Save
Exit Sub
End If
Next
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You can achieve this in different ways.
One option is to create a new macro with the actions that you want to take further and to replace the line Exit Sub with calling your new macro.
And in the new macro you can add the command End before Exit sub in order to complete it (If that's the last operation you would like to perform).
 
Last edited:
Upvote 0
How about
Code:
For Each Cell In ActiveSheet.Range("SBISGM[Date]")
   If Cell.Value >= Date And Cell.Value < Date + 15 Then
      Cell.Select
      ActiveWorkbook.Save
      Exit For
   End If
Next
' now do something else
End Sub
 
Upvote 0
Thanks @Fluff for quick response.

It did the Magic...

Thanks again.

How about
Code:
For Each Cell In ActiveSheet.Range("SBISGM[Date]")
   If Cell.Value >= Date And Cell.Value < Date + 15 Then
      Cell.Select
      ActiveWorkbook.Save
      Exit For
   End If
Next
' now do something else
End Sub
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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