How do I create a sub function

  • Thread starter Thread starter atoth22
  • Start date Start date
A

atoth22

How do I create a function that is sent two variables. I want it be sen
a variable called i and another FinalRow. Then I want it to do it'
thing. I want to be able to call this function at anytime in my macr
by just typing FunctionName(i,FinalRow). Here what I want to b
included in my function

n = i
For n = i To FinalRow
If (Range("A" & n).Value) = "" And (Range("B" & n).Value) = 1 An
(Range("C" & n).Value) = 1 And (Range("D" & n).Value) = "" Then
Rows(n & ":" & n).Cut
Rows(i & ":" & i).Insert Shift:=xlDown
End If
Next n

Thank yo
 
Function MyFunction(I As Integer, FinalRow As Integer) As String

Your code here
MyFunction = Result
End Function

But I think what you want is something else because a function is used for
returning a value.
What you might want is a Sub.

Public Sub MySub(I As Integer, FinalRow As Integer)
Your Code Here
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