ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   calling a macro within an excel formula (https://www.excelbanter.com/excel-programming/438474-calling-macro-within-excel-formula.html)

Rahne059

calling a macro within an excel formula
 
Is it possible to call a macro from within and excel 2003 If statement as
follows:

=If(IF(M2 <=LASTSN,copymacro[then i want to call a print macro and move down
a row and repeat this formula for M3, until M# is no longer <= LASTSN)

I have been unsuccessfully trying to find and modify macros that others used
to create sequential serial numbers for a week now, and have not yet got them
to work; probably because I have never worked with Visual Basic before and do
not really understand its syntax.

--
rahne059

Rahne059

calling a macro within an excel formula
 
Addon - here is the partial macro i wrote so far:

Sub copypaste()
'
' copypaste Macro
' Macro recorded 1/15/2010 by rstembler
'
' Keyboard Shortcut: Ctrl+a
'
Range("M2").Select
Selection.Copy
ActiveWindow.LargeScroll ToRight:=-1
Range("D5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets(Array("Layup Worksheet Pg1 ", "Layup Worksheet Pg2", "Layup
Worksheet Pg3" _
)).Select
Sheets("Layup Worksheet Pg1 ").Activate
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.LargeScroll ToRight:=1

AT THIS POINT IT NEEDS TO ROLL BACK TO THE IF STATEMENT AND THEN CONTINUE TO
CHANGE RANGES AND LOOP UNTIL M# LASTSN

Range("M3").Select
Selection.Copy
ActiveWindow.LargeScroll ToRight:=-1
Range("D5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub


I USED TO BE ABLE TO DO THIS ON A WANG ALL-IN-ONE MAINFRAME COMPUTER, BUT
OBVIOUSLY VISUAL BASIC USES DIFFERENT RULES.
--
rahne059


"rahne059" wrote:

Is it possible to call a macro from within and excel 2003 If statement as
follows:

=If(IF(M2 <=LASTSN,copymacro[then i want to call a print macro and move down
a row and repeat this formula for M3, until M# is no longer <= LASTSN)

I have been unsuccessfully trying to find and modify macros that others used
to create sequential serial numbers for a week now, and have not yet got them
to work; probably because I have never worked with Visual Basic before and do
not really understand its syntax.

--
rahne059


Dave Peterson

calling a macro within an excel formula
 
Nope.

You can use a user defined function in that formula, but (almost) all that it
can do is return a value to the cell that contains that function/formula.

Maybe you can add a button from the Forms toolbar and assign your macro to
that. Then tell the user to hit the button to run the macro when they need it.

rahne059 wrote:

Is it possible to call a macro from within and excel 2003 If statement as
follows:

=If(IF(M2 <=LASTSN,copymacro[then i want to call a print macro and move down
a row and repeat this formula for M3, until M# is no longer <= LASTSN)

I have been unsuccessfully trying to find and modify macros that others used
to create sequential serial numbers for a week now, and have not yet got them
to work; probably because I have never worked with Visual Basic before and do
not really understand its syntax.

--
rahne059


--

Dave Peterson


All times are GMT +1. The time now is 10:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com