Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA 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 November 4th, 2006, 04:56 PM
Authorized User
 
Join Date: Nov 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Do while loop

I am not very experienced with VBA. I cannot figure out what is wrong with the below code. Please help me -

j = 1
Do While Not Cells(12, j) = "Product"
    j = j + 1
Loop
MsgBox "Product column = " & j

Well, in row 12th, some column has value 'Product' and i'm trying to find out which column has it.
Please help me
Thanks
 
Old November 4th, 2006, 06:08 PM
Registered User
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tested it and it seemed to work fine. Remember to translate the value of j (a number) to a letter. 1=A, 2=B ETC

or to get address
try this

Sub test()
Dim R As Range
Set R = Cells(12, 1)

j = 1
Do While Not R.Offset(, j) = "Product"
    j = j + 1
Loop
MsgBox "Product column = " & R.Offset(, j).Address

End Sub



Steve
 
Old November 5th, 2006, 04:38 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Text test is case sensitive.
Change your test like this

Do While Not UCase(Cells(12, j)) = "PRODUCT"


-vemaju
 
Old November 6th, 2006, 01:04 PM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Instead of using ="PRODUCT" try using the LIKE statement

Do While Not UCase(Cells(12, j)) LIKE "*PRODUCT*"
    j = j + 1
Loop

MsgBox "Product column = " & j

Maybe the word "Product" is not at the beginning of the cell
 
Old November 6th, 2006, 11:30 PM
Authorized User
 
Join Date: Nov 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanku all for ur help.
 It worked.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
For....Loop kliu9 Excel VBA 5 February 10th, 2005 06:43 AM
Do Loop junemo Beginning PHP 8 July 28th, 2004 02:58 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.