Variable Macro

  • Thread starter Thread starter Ronbo
  • Start date Start date
R

Ronbo

Trying again, I am looking for a way to create a variable
macro or a macro that contains a variable. I want the
macro to acquire a variable number (X) and then run a
macro X times. Ex - Macro "Print" 'print Hello and move
down one cell; cell a1 = 3 (the variable #), so the new
macro would = run "Print 3 times" =
Hello
Hello
Hello

Thanks to those who have helped before and to any
additional help.
 
Sub MyPrint()
ActiveCell.Value = "Print"
ActiveCell.Offset(1,0)
End Sub

sub ValueMacro()
Dim x as Variant
Range("A1").Value = 3
x = Range("A1").Value
if not isnumeric(x) then exit sub
range("C3").Select
for i = 1 to x
MyPrint
Next
End Sub
 
-----Original Message-----
Sub MyPrint()
ActiveCell.Value = "Print"
ActiveCell.Offset(1,0)
End Sub

sub ValueMacro()
Dim x as Variant
Range("A1").Value = 3
x = Range("A1").Value
if not isnumeric(x) then exit sub
range("C3").Select
for i = 1 to x
MyPrint
Next
End Sub


--
Regards,
Tom Ogilvy





.

Thanks a lot. With a little tweaking it works perfect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top