get2noesks
New Member
- Joined
- Jul 15, 2015
- Messages
- 24
Hi,
I am trying to make a collection of rows and columns on a successful search of the text found. While executing the code I get a run time error message "Run-time error '1004' Application Defined or object defined error".
Code is as followed:
Function getValuesToSort() As Collection
Dim findString As String
Dim cntrlRow, cntrlCol As Integer
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim var As Collection
Set var = New Collection
Set WS1 = Worksheets("Sheet1")
Set WS2 = Worksheets("Sheet2")
cntrlRow = 3
cntrlCol = 2
Dim iRow, iCol, i, j As Integer
iRow = iCol = 1
While WS2.Cells(cntrlRow, cntrlCol) <> ""
findString = WS2.Cells(cntrlRow, cntrlCol)
While WS1.Cells(iRow, iCol).Value <> ""
If findString = WS1.Cells(iRow, iCol) Then
var.Add (iRow)
var.Add (iCol)
End If
MsgBox var
iCol = iCol + 1
Wend
cntrlRow = cntrlRow + 1
Wend
Set getValuesToSort = var
End Function
Please advise.
I am trying to make a collection of rows and columns on a successful search of the text found. While executing the code I get a run time error message "Run-time error '1004' Application Defined or object defined error".
Code is as followed:
Function getValuesToSort() As Collection
Dim findString As String
Dim cntrlRow, cntrlCol As Integer
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim var As Collection
Set var = New Collection
Set WS1 = Worksheets("Sheet1")
Set WS2 = Worksheets("Sheet2")
cntrlRow = 3
cntrlCol = 2
Dim iRow, iCol, i, j As Integer
iRow = iCol = 1
While WS2.Cells(cntrlRow, cntrlCol) <> ""
findString = WS2.Cells(cntrlRow, cntrlCol)
While WS1.Cells(iRow, iCol).Value <> ""
If findString = WS1.Cells(iRow, iCol) Then
var.Add (iRow)
var.Add (iCol)
End If
MsgBox var
iCol = iCol + 1
Wend
cntrlRow = cntrlRow + 1
Wend
Set getValuesToSort = var
End Function
Please advise.