PDA

View Full Version : Solved: Problem with declarations and Str function



pepe90
07-26-2011, 09:10 AM
Hello, the problem I have is that running a macro I made on Excel 2003 on the 2007 version it demands all variables declarations, so I did it, but now it shows an error on the Str function. Here is the code:
Public Sub reporte(ByRef maquinas() As String, ByRef cantidad_maquinas() As Double)
Dim n, fila, i, j, maqs_encontradas As Integer
n = UBound(maquinas)
fila = 1
For i = 0 To n
maqs_encontradas = 0
With Sheets("REPORTE")
.Cells(fila, 1) = Str(cantidad_maquinas(i)) & " " & maquinas(i)
.Cells(fila + 1, 1) = "MÁQUINA"
.Cells(fila + 1, 2) = "PLACA"
.Cells(fila + 1, 3) = "UBICACIÓN"
.Cells(fila + 1, 4) = "ESTADO"
End With
Next
end sub


It marks "Str" and says that doesn't find the proyect or library.

Thanks in advance

Kenneth Hobs
07-26-2011, 09:21 AM
Use CStr but a string conversion is explicit since you are using concatenation.

Always use as the first line of code:
Option Explicit

CatDaddy
07-26-2011, 12:24 PM
do you even have to convert to a string to concatenate?

Kenneth Hobs
07-26-2011, 12:49 PM
When concatenating a double to a string, I would use CStr() for the double.

CatDaddy
07-26-2011, 02:23 PM
for good practice or out of necessity?

Aflatoon
07-27-2011, 01:54 AM
To get that error (though Str is unnecessary as has been remarked) I would suspect you have a missing reference. In the VB Editor, select Tools -> References and see if any are prefixed with 'MISSING:'

pepe90
07-27-2011, 12:41 PM
The problem was solved using CStr. Thanks everyone ;)