Crear una sub rutina que pueda llamar

Hola a todos..
Lo que necesito es crear una subrutina que cuando la llame me ejecute un código, y quiero que a este le pueda introducir los valores de las variables con las que debe trabajar, creo haberlo intentado pero cuando la llamo me aparece un error de "seesperaba un =" si le pongo = me aparece se esperaba una sub función o una variable, esta es mi subrutina
Public Sub contabilizar(cta, doc, debe, haber)
CLASE = Left(cta, 1)
GRUPO = Left(cta, 2)
cuenta = Left(cta, 4)
TIPO = Len(cta)
If TIPO < 6 Then
    cuenta = cta ' presumimos que es una subcuenta
End If
If CLASE = 1 Then
    CLASE = "ACTIVO"
ElseIf CLASE = 2 Then
    CLASE = "PASIVO"
ElseIf CLASE = 3 Then
    CLASE = "PATRIMONIO"
ElseIf CLASE = 4 Then
    CLASE = "INGRESOS"
ElseIf CLASE = 5 Then
    CLASE = "GASTOS"
ElseIf CLASE = 6 Then
    CLASE = "COSTOS"
ElseIf CLASE = 8 Then
    CLASE = "CTAS_DE_ORDEN"
ElseIf CLASE = 9 Then
    CLASE = "CTAS_DE_ORDEN"
End If
ruta = "Y:\"
carpeta = "CONTABILIDAD"
Libro = CLASE
texto = ruta & carpeta & "\" & Libro & ".xlsx"
Workbooks.Open texto, UpdateLinks:=False, Password:="rON44991043"
Workbooks(Libro & ".xlsx").Sheets(cuenta).Activate
Sheets(cuenta).Select
Range("A2").Select  'selecciono la celda A2
Selection.EntireRow.Insert
Range("A2").Value = (Range("A3")) + 1
Cells(2, 2).Value = doc '
Cells(2, 3).Value = TextBox109 ' NO DE documento
Cells(2, 4).Value = TextBox37 ' nit a quien lo aplicamos
Cells(2, 5).Value = TextBox38 ' nombre
Cells(2, 6).Value = TextBox108 ' fEcha de aplicacion
Cells(2, 7).Value = Val(debe) 'VALOR  debe
Cells(2, 8).Value = Val(haber) 'VALOR  haber
Cells(2, 10).Value = Now()
Cells(2, 11).Value = TextBox_USUARIO.Value
If CLASE = "ACTIVO" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) + (Val(Cells(2, 7).Value)) - (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "PASIVO" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "PATRIMONIO" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
ElseIf CLASE = "INGRESOS" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "GASTOS" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
ElseIf CLASE = "COSTOS" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) + (Val(Cells(2, 7).Value)) - (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "CTAS_DE_ORDEN" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
ElseIf CLASE = "CTAS_DE_ORDEN" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
End If
Sheets(CLASE).Select
filalibre = Range("A2").End(xlDown).Offset(1, 0).Row 'la variable filalibre guarda el nro. De la primer celda vacía.
dato = cuenta
rango = "A2:A" & filalibre
Set midato = ActiveSheet.Range(rango).Find(dato, LookIn:=xlValues, LookAt:=xlWhole)
If Not (midato) Is Nothing Then
    ubica = midato.Address(False, False)
    Range(ubica).Offset(0, 2).Value = Val(Range(ubica).Offset(0, 2).Value) + Val(debe) ' PREGUNTAR COMO SERIA EN CADA CASO
End If
contabilizar = Cadena
End Sub

1 respuesta

Respuesta
1
Si quieres que te retorne un valor, no debes utilizar Public Sub , sino Public Function
Básicamente lo que deseo es que no me deveulva ningún valor
Si no quieres que retorne valores, la penúltima línea - contabilizar = Cadena - está sobrando y el llamado al procedimiento debería ser:
Contabilizar var1, var2, var3, var4
Nótese que las variables no están entre paréntesis.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas