Want Macro to continue after a first action

SanjayGulatiMusafir

Board Regular
Joined
Sep 7, 2018
Messages
69
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
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

KKaren

New Member
Joined
Jan 13, 2018
Messages
33
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
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
 

SanjayGulatiMusafir

Board Regular
Joined
Sep 7, 2018
Messages
69
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,123,312
Messages
5,600,887
Members
414,414
Latest member
neil_c

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
Top