0

I have my main sub named DXF() that is called by a button in my excel sheet. DXF() calls another sub named reorganisation(FirstLine, LastLine). Now I want reorganisation to call another sub named sens(LastLine). I did it like this in reorganisation(FirstLine, LastLine) :

Sub reorganisation(FirstLine, LastLine)
[...]
Dim iLine As Integer, Ligne As Integer

With ActiveSheet

Set Temp = Range(.Cells(1000, 1000), .Cells(1000, 1013))

For iLine = FirstLine To LastLine
    [...]
    Ligne = iLine + 1
            Do While Ligne <= LastLine      ''' Organisation par des segments suivant le point de base
                [...]
            Loop
    sens iLine            '''' The error is here
Next iLine
End With
End Sub

Everything works well in this sub except where I call sens.

Here is the sub sens.

Sub sens(LastLine)
Dim iLine, Ligne As Integer
With ActiveSheet
    For iLine = 3 To LastLine
        [...]
    Next iLine
End With
End Sub

So this gives me the error "Compilation error : sub, function or property needed". I really don't know why it makes this because there is no variable type problem, everything is integer so... If anyone can tell where the problem comes from thanks in advance !

Jack
  • 695
  • 10
  • 29

2 Answers2

1

It was actually a really simple mistake. I have a variable that I created a long time ago (so I forgot about it) which was named the same way as my sub. Thank you everyone.

Jack
  • 695
  • 10
  • 29
-1

Make the Sub sens(LastLine) a public Sub. Thus, it would be visible from the worksheet. Like this:

Public Sub sens(LastLine)

What is the difference between Dim, Global, Public, and Private as Modular Field Access Modifiers?


This is a simple code that works:

Public Sub Reorganisation()    
    Dim iLine As Long
    iLine = 5
    Sens iLine        
End Sub

Public Sub Sens(LastLine As Long)    
    MsgBox "It works"        
End Sub
Vityata
  • 42,633
  • 8
  • 55
  • 100
  • This doesn't work either... Plus all of these subs are in the same module so I imagine I shouldn't get this problem – Jack Aug 09 '18 at 09:12
  • Can you write `Sub sens(LastLine as Integer)` instead of `Sub sens(LastLine)`? – Vityata Aug 09 '18 at 09:14
  • 1
    so is using `Public` the correct instead of using `call`? Do you know when this was implemented? – Dan Aug 09 '18 at 09:18
  • @JackA - try the "simple code" from my answer and then build up your code around it. – Vityata Aug 09 '18 at 09:18
  • @Dan - well, it really depends on how you are using VBA. In general, it is advised to avoid `Call`, because it is a bit useless - https://stackoverflow.com/questions/479891/what-does-the-call-keyword-do-in-vb6 However, the code would not be broken because of it. – Vityata Aug 09 '18 at 09:20
  • @Dan - `Public` and `Call` do not have anything to do with each other. They are serving different purposes. – Vityata Aug 09 '18 at 09:21