decode loop
hi all
this loop is supposed to count how many times the 2 numbers I select from my combo boxes appear together in the same column of my excel spread sheet but always gives "10" as the asnwer could somebody tell me where the mistake is??
thanks
lneilson
Dim intcount As Integer
Dim looper As Integer
Dim combo1number As Integer
Dim combo2number As Integer
Dim i As Integer
Dim exists1, exists2 As Boolean
'get the numbers you wish to search for
combo1number = 1
combo2number = 2
intcount = 0
For looper = 1 To Me.UsedRange.Columns.Count
'i.e loop through each column
exists1 = False
exists2 = False
For i = 1 To Me.UsedRange.Rows.Count
'search all rows
If Me.Range("A1").Offset(i - 1, looper - 1) = combo1number Then exists1 = True
If Me.Range("A1").Offset(i - 1, looper - 1) = combo2number Then exists2 = True
Next
'if both numbers appear in a column, count it
If exists1 And exists2 Then intcount = intcount + 1
Next
Text2.text= intcount
wb.Close
xlApp.Quit
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing
|