calling function form within sub

  • Thread starter Thread starter Dirk
  • Start date Start date
D

Dirk

All

I am trying to call a function form within a sub, but VBA doesn't
accept the swapRows function and asks for a =. Why?

Dirk

Function swapRows(areaSwap1 As Range, areaSwap2 As Range)
' a lot of code
End Function

Sub schedule()
Dim ran As Range
Dim num As Integer

Set ran = InputBox("select range including heading for columns",
Type:=8)
num = ran.Rows.Count
For i = 2 To num
If isempty(ran(i, 2)) Then swapRows(ran.Row(i),ran.Row(i+1))
Next i

End Sub
 
change it to

If isempty(ran(i, 2)) Then call swapRows(ran.Row(i),ran.Row(i+1))


or

If isempty(ran(i, 2)) Then swapRows ran.Row(i), ran.Row(i+1)

this is the syntax of VBA/VB.
 

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