I need procedure to my codes after click button from the second time

Omar M

Board Regular
Joined
Jan 11, 2024
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
Hi Experts,
I have code ,running the code from the first time but if I click the button again then should call
sub macro1() before running my original code is sub test().
every time save and close the file.
the first time when run my original code will be when open the file .
I hope this clear guys.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Declare a module level variable (right at the top of the module, something like Dim bolRan As Boolean).
In your 1st sub near the beginning, test bolRan. If it is false, run first sub. If True, call 2nd sub which will then run. Then execution will continue in 1st sub. I suspect that is what you want. In 1st sub just before it will finish or exit, put bolRan = True. Thus when 1st sub runs first time, bolRan becomes True. Upon second button click, 2nd sub will be called from first sub because bolRan is True.

Next time you open wb, bolRan will be false before first click of command button.
 
Upvote 0
Hi
thanks for guiding me.
to be honest I have no idea to that. I have no expriene to write some lines by vba.
I hope to do that for me if you have free time.
 
Upvote 0
You said you already have code. So start by posting that?
Please use code tags for posting code (click VBA button on posting toolbar and paste within the resulting tags).
 
Upvote 0
Hi again !
just I want to know before I post codes, does procedure make difference based on code type, or I can implment for any code?
 
Upvote 0
I don't know what you mean by code type. I consider code types to be like VBA, HTML, Perl, Java, Python etc. Surely that is not what you mean.
As long as the code is Excel VBA it should be OK.
 
Upvote 0
let's take simple example:
VBA Code:
Sub macro1()
If Range("A1").Value="yes" Then
Range("A2").Value="OMAR"
End If
End Sub

VBA Code:
Sub test()

Columns("C:C") = "@"

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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