Hi, I am currently having some difficulties with this sunroutine that I created. My 2 dimensional array is empty.
- This code is within my UserForm1
- this sub is suppose to first select the WorkSheets("Eng lish"). The sheet contains col A, col B & col C. The sub will goto each row, if there is a cell value that matches the search criteria then all the cell values of that particular row is put into my 2-dimensional array.
- my while loop does not end. Is there something wrong with my code ?
Any ideas would be greatly appreciated !
--------------------------------------------------------------------------
Sub getResult(x, y, z)
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim cell1 As String
Dim cell2 As String
Dim cell3 As String
Dim tempStr1 As String
Dim tempStr2 As String
Dim tempStr3 As String
Dim counter As Integer
ThisWorkbook.Wo rksheets("Engli sh").Activate
'create 2 dimensional array -- 100 rows & 3 columns / note: lowerbound is 0
Dim myarray(100, 3)
str1 = x
str2 = y
str3 = z
'--------- Checking code ---------
MsgBox "str1 = " + str1 + " and str2 = " + str2 + " and str3 = " + str3
'---- looping structure of myarray -----
'the loop will check every row in Sheet1(English) and compare
'whether row 1 (col A, col B, col C) matches str1, str2 str3.
'If there is match to any str1 or str2 or str3 then the cell values will be read and placed into myarray()
counter = 0
cell1 = counter + 1
cell2 = counter + 1
cell3 = counter + 1
While Worksheets("Eng lish").Range("A " + cell1 + "") <> Empty And Worksheets("Eng lish").Range("B " + cell2 + "") <> Empty And Worksheets("Eng lish").Range("A " + cell1 + "") <> Empty
tempStr1 = Worksheets("Eng lish").Range("A " + cell1 + "").Value
tempStr2 = Worksheets("Eng lish").Range("B " + cell2 + "").Value
tempStr3 = Worksheets("Eng lish").Range("C " + cell3 + "").Value
'--------- Checking code ---------
MsgBox "tempStr1 = " + tempStr1 + " and tempStr2 = " + tempStr2 + " and tempStr3 = " + tempStr3
If tempStr1 = str1 Or tempStr3 = str2 Or tempStr3 = str3 Then
myarray(counter , 0) = tempStr1
myarray(counter , 1) = tempStr2
myarray(counter , 2) = tempStr3
counter = counter + 1
End If
tempStr1 = vbNullString
tempStr2 = vbNullString
tempStr3 = vbNullString
Wend
Call showResult(myar ray)
End Sub
- This code is within my UserForm1
- this sub is suppose to first select the WorkSheets("Eng lish"). The sheet contains col A, col B & col C. The sub will goto each row, if there is a cell value that matches the search criteria then all the cell values of that particular row is put into my 2-dimensional array.
- my while loop does not end. Is there something wrong with my code ?
Any ideas would be greatly appreciated !
--------------------------------------------------------------------------
Sub getResult(x, y, z)
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim cell1 As String
Dim cell2 As String
Dim cell3 As String
Dim tempStr1 As String
Dim tempStr2 As String
Dim tempStr3 As String
Dim counter As Integer
ThisWorkbook.Wo rksheets("Engli sh").Activate
'create 2 dimensional array -- 100 rows & 3 columns / note: lowerbound is 0
Dim myarray(100, 3)
str1 = x
str2 = y
str3 = z
'--------- Checking code ---------
MsgBox "str1 = " + str1 + " and str2 = " + str2 + " and str3 = " + str3
'---- looping structure of myarray -----
'the loop will check every row in Sheet1(English) and compare
'whether row 1 (col A, col B, col C) matches str1, str2 str3.
'If there is match to any str1 or str2 or str3 then the cell values will be read and placed into myarray()
counter = 0
cell1 = counter + 1
cell2 = counter + 1
cell3 = counter + 1
While Worksheets("Eng lish").Range("A " + cell1 + "") <> Empty And Worksheets("Eng lish").Range("B " + cell2 + "") <> Empty And Worksheets("Eng lish").Range("A " + cell1 + "") <> Empty
tempStr1 = Worksheets("Eng lish").Range("A " + cell1 + "").Value
tempStr2 = Worksheets("Eng lish").Range("B " + cell2 + "").Value
tempStr3 = Worksheets("Eng lish").Range("C " + cell3 + "").Value
'--------- Checking code ---------
MsgBox "tempStr1 = " + tempStr1 + " and tempStr2 = " + tempStr2 + " and tempStr3 = " + tempStr3
If tempStr1 = str1 Or tempStr3 = str2 Or tempStr3 = str3 Then
myarray(counter , 0) = tempStr1
myarray(counter , 1) = tempStr2
myarray(counter , 2) = tempStr3
counter = counter + 1
End If
tempStr1 = vbNullString
tempStr2 = vbNullString
tempStr3 = vbNullString
Wend
Call showResult(myar ray)
End Sub
Comment