tomzko
12-27-2015, 07:24 PM
Hi, im new to these forum and also in VBA, ive never used it before and i dont know any other programing languaje.
Here is my question:
i made a Sub. in a module that from data of cells generates a matrix that ill need to use later (te sub is called GenerarMatriz() )
then in sheet1 i made a Sub. that is called Prueba() that executes GenerarMatriz but when i press play an error occurs, here are the codes:
(i want the answer for the specific question, my intention is not to analyze the full code) :),
Module:
Sub GenerateMatriz()
Dim SumaTotalCamiones, TotalClase, i As Integer
Dim Matriz() As Integer
i = 0
TotalClaseA = Worksheets("hoja1").Cells(4, 1).Value
TotalClaseB = Worksheets("hoja1").Cells(4 + 1, 1).Value
TotalClaseC = Worksheets("hoja1").Cells(4 + 2, 1).Value
SumaTotalCamiones = Worksheets("hoja1").Cells(4, 1).Value + Worksheets("hoja1").Cells(5, 1).Value + Worksheets("hoja1").Cells(6, 1).Value
ReDim Matriz(SumaTotalCamiones - 1, 3)
For j = 0 To TotalClaseA
n = 0
For n = 0 To 3
Matriz(i, n) = Worksheets("hoja3").Cells(i + 1, n + 1).Value
Next n
Next j
For j = TotalClaseA To TotalClaseA + TotalClaseB
n = 0
For n = 0 To 3
Matriz(i, n) = Worksheets("hoja3").Cells(i + 1, n + 1).Value
Next n
Next j
For j = TotalClaseA + TotalClaseB To TotalClaseA + TotalClaseB + TotalClaseC
n = 0
For n = 0 To 3
Matriz(i, n) = Worksheets("hoja3").Cells(i + 1, n + 1).Value
Next n
Next j
End Sub
Sheet1: (Where i want to use my GenerarMatriz)
Sub Test()
GenerateMatriz
Cell(1, 1) = Matriz(1, 1)
End Sub
Thanks for your time!
Here is my question:
i made a Sub. in a module that from data of cells generates a matrix that ill need to use later (te sub is called GenerarMatriz() )
then in sheet1 i made a Sub. that is called Prueba() that executes GenerarMatriz but when i press play an error occurs, here are the codes:
(i want the answer for the specific question, my intention is not to analyze the full code) :),
Module:
Sub GenerateMatriz()
Dim SumaTotalCamiones, TotalClase, i As Integer
Dim Matriz() As Integer
i = 0
TotalClaseA = Worksheets("hoja1").Cells(4, 1).Value
TotalClaseB = Worksheets("hoja1").Cells(4 + 1, 1).Value
TotalClaseC = Worksheets("hoja1").Cells(4 + 2, 1).Value
SumaTotalCamiones = Worksheets("hoja1").Cells(4, 1).Value + Worksheets("hoja1").Cells(5, 1).Value + Worksheets("hoja1").Cells(6, 1).Value
ReDim Matriz(SumaTotalCamiones - 1, 3)
For j = 0 To TotalClaseA
n = 0
For n = 0 To 3
Matriz(i, n) = Worksheets("hoja3").Cells(i + 1, n + 1).Value
Next n
Next j
For j = TotalClaseA To TotalClaseA + TotalClaseB
n = 0
For n = 0 To 3
Matriz(i, n) = Worksheets("hoja3").Cells(i + 1, n + 1).Value
Next n
Next j
For j = TotalClaseA + TotalClaseB To TotalClaseA + TotalClaseB + TotalClaseC
n = 0
For n = 0 To 3
Matriz(i, n) = Worksheets("hoja3").Cells(i + 1, n + 1).Value
Next n
Next j
End Sub
Sheet1: (Where i want to use my GenerarMatriz)
Sub Test()
GenerateMatriz
Cell(1, 1) = Matriz(1, 1)
End Sub
Thanks for your time!