getting started...

B

bell

Hi,
is it possible to create a macro that receives arguments? What I mean is
without using offset, for example:
one time to run the macro with cells A1 A2 as parameters and write the
result into B2
and another time to run the macro over cells D5 E9 and write the result
into F8?

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Business Software Galore!
Free Excel Forum http://www.ozgrid.com/forum ***
 
F

Frank Kabel

Hi
you may create a user defined function for this and insert
this function in the target cell. e.g. a function lik

Public function do_something(rng1 as range, rng2 as range)
do_something=rng1.value+rng2.value
end function

Now put the following in cell B2
=DO_SOMETHING(A1,A2)
 
J

JE McGimpsey

One way:

Public Sub foo(bar1 As Range, bar2 As Range, bar3 As Range)
bar3.Value = bar1.Value & " " & bar2.Value
End Sub

Call from a Sub as

foo Range("D5"), Range("E9"), Range("F8")


Or, if you want to call a UDF from the worksheet:

Public Function foo(bar1 As Range, bar2 As Range) As String
foo = bar1.Value & " " & bar2.Value
End Function

Call as

F8: =foo(D5, E9)
 

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

Top