MisterSrosis
New Member
- Joined
- Jul 30, 2014
- Messages
- 12
Code:
'For future purposes it's best to probably find a way to condesne the repating code for the 2 cases of whether user knows 1 or 2 facts about the component that he/she is trying to find
'Returns array of cell addresses and from which workbook and worksheet theyu came from.
Private Function FilterResultsEvenFurther(Results() As Variant) As Variant
Dim ct As Long
Dim ct2 As Long
Dim wkbookAndWksheetInfo As String
Dim wkb As Workbook
Dim wrdArr() As String
Dim fileN As Variant
Dim sht As Worksheet
Dim c As Range
Dim arrCnt As Long
Dim cAddressArr() As Variant
Dim conf As Variant
Dim columnBeingAnalyzed() As Variant
Dim ce As Range
Dim filterS As String
Dim filterS2 As String
conf = MsgBox("Do you think you know 2 general facts about your specific component? Example: When describing a resistor we consider resistance value, what type of resistor it is (power,variable,ceramic)", vbYesNo)
arrCnt = 0
If conf = vbYes Then
filterS = Application.InputBox("Enter category that your sepcific component belongs to(Ex: resistor,the categories a resistor can belong to are power, variable, high voltage etc.):")
filterS2 = Application.InputBox("Enter any further Identification/value/ID number of Component")
For ct = 0 To UBound(Results)
wkbookAndWksheetInfo = Results(ct)
wrdArr = Split(wkbookAndWksheetInfo)
fileN = "labInventory" & "\" & wrdArr(0)
Set wkb = Workbooks.Open(fileN)
Set sht = wkb.Sheets(wrdArr(1))
sht.Activate
For Each c In sht.UsedRange.Cells
If InStr(c.Value, filterS) > 0 Then
'checking the column in which the first filterstring was found for the 2nd filterString
columnBeingAnalyzed = c.Column
For Each ce In columnBeingAnalyzed
If InStr(c.Value, filterS2) > 0 Then
arrCnt = arrCnt + 1
cAddressArr(arrCnt) = c.Address + "" + sht.Name + "" + wkb.Name
End If
Next ce
End If
Next c
Next ct
Else
filterS2 = Application.InputBox("Enter any further Identification/value/ID number of Component")
For ct = 0 To UBound(Results)
arrCnt = 0
wkbookAndWksheetInfo = Results(ct)
wrdArr = Split(wkbookAndWksheetInfo, "")
fileN = "labInventory" & "\" & wrdArr(0)
Set wkb = Workbooks.Open(fileN)
Set sht = wkb.Sheets(wrdArr(1))
sht.Activate
For Each c In sht.UsedRange.Cells
If InStr(c.Value, filterS2) > 0 Then
arrCnt = arrCnt + 1
cAddressArr(arrCnt) = c.Address + "" + sht.Name + "" + wkb.Name
End If
Next c
Next ct
End If
FilterResultsEvenFurther = cAddressArr
End Function
The problem lies in this part
Code:
For Each c In sht.UsedRange.Cells
If InStr(c.Value, filterS) > 0 Then
'checking the column in which the first filterstring was found for the 2nd filterString
'When the cell with the keyword is found, I want to somehow reference the entire column the cell was found 'in, and loop over all of the cells being used in that column to find a second filterstring = filterS2
columnBeingAnalyzed = c.Column
For Each ce In columnBeingAnalyzed
If InStr(c.Value, filterS2) > 0 Then
arrCnt = arrCnt + 1
cAddressArr(arrCnt) = c.Address + "" + sht.Name + "" + wkb.Name
End If
Next ce
End If
Next c