Hi All
I have prepare code that will store data in the array & then will get the data from the array, which will be stored in variable.
My code have 2 variant arrays and code work fine for one array but for 2nd array, it give error that variable not defined. Kindly check the code that where it has error. I am attaching the code.
code is given below.
>>> use code - tags <<<
I have prepare code that will store data in the array & then will get the data from the array, which will be stored in variable.
My code have 2 variant arrays and code work fine for one array but for 2nd array, it give error that variable not defined. Kindly check the code that where it has error. I am attaching the code.
code is given below.
>>> use code - tags <<<
Code:
Option Explicit
Sub course()
Dim lecttime(), stdntdat() As Variant
Dim lrw, lcl, lrow, lcol As Long, a, b, c, d As Long
Dim str As Variant
'cal last row
lrw = Sheet1.Cells.Find(What:="*", lookat:=xlPart, LookIn:=xlFormulas, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
'cal last column
lcl = Sheet1.Cells.Find(What:="*", lookat:=xlPart, LookIn:=xlFormulas, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
ReDim lecttime(lrw, lcl)
'MsgBox lecttime(lrw, lcl)
For a = 1 To lrw
For b = 1 To lcl
lecttime(a - 1, b - 1) = Sheet1.Cells(a + 1, b).Value
b = b + 1
Next
a = a + 1
Next
ReDim Preserve lecttime(lrw, lcl)
Sheet1.Cells(12, 8).Value = lecttime(0, 0)
'cal last row
lrow = Sheet2.Cells.Find(What:="*", lookat:=xlPart, LookIn:=xlFormulas, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
'cal last column
lcol = Sheet2.Cells.Find(What:="*", lookat:=xlPart, LookIn:=xlFormulas, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
ReDim stdntdat(lrow, lcol)
For c = 1 To lrow
For d = 1 To lcol
stdntdat(c - 1, d - 1) = Sheet2.Cells(c + 1, d).Value
Next
Next
ReDim Preserve stdndat(lrow, lcol) ' Error line'
c = 0
d = 0
Dim str As Variant
steet.Cells(22, 10).Value = stdndat(c, d) ' Error line'
End Sub
Attachments
Last edited by a moderator: