Wrox Programmer Forums
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 6th, 2003, 12:18 PM
Registered User
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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??


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

'if both numbers appear in a column, count it
If exists1 And exists2 Then intcount = intcount + 1
Text2.text= intcount



Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing

Old August 6th, 2003, 12:32 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi

hi there..

some things i see...
- where do you open the xls??
- why do you use me.. if you are opening a xls?? me is the current form...
- are you programing inside Excel?? then dont use offset, just set the range and use and i think you need formularr1p1 or something like that
- use a loop, not a for, so when you have 2 trues you just go out the loop
- the range is not column, rows??? i think you have misplaced the two of them...


Gonzalo Bianchi

Similar Threads
Thread Thread Starter Forum Replies Last Post
Option for decode yogeshyl SQL Language 0 July 6th, 2008 11:52 PM
Decode function to display result in same row yogeshyl SQL Language 0 July 2nd, 2008 12:40 AM
[HOW TO] Decode / Decrypt Sha1 ??? oscarestany PHP How-To 1 August 6th, 2007 05:49 PM
Encode & Decode melvik SQL Server 2000 2 June 2nd, 2004 09:23 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.