Macro runs on cell value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I run the same macro or Subroutine from different Cells.
for example
I want the Macro 'MyMacro()' to use the value in the cell.
However I'm Not sure how to pass the string value in the cell
to the macro

If Cell A1 had 'Supplier'
MyMacro would look like this
=MyData(A1)

I want to use the same Subroutine for other
Cell value for example

If Cell A2 has 'Customer'
MyMacro would look like this
=MyData(A2)
 
Either this...

call MyMacro(Range("A2"))

Public Sub MyMacro(ByVal Cell As Range)
MsgBox Cell.Value
End Sub

or....

call MyMacro("A2")

Public Sub MyMacro(ByVal Cell As String)
MsgBox Range(cell).Value
End Sub
 

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