Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 April 13th, 2005, 01:36 PM
Authorized User
 
Join Date: Apr 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default count (i) while looping - help!

I'm trying to loop through an excel spreadsheet. I have alot of my code down pat except for this one piece. I can't figure out how to get the data from within a loop so that I can see what is in A1, A2, A3, ...

This is what I have for code (for that portion):

NOTE: i is set to start out as 1

Set MyColumns_Range = Range(wsData.Cells(1, "A"), wsData.Cells(1, "A").End(xlDown))
    For Each c In MyColumns_Range
        fund = Range("A" + i).Value
        trans_type = Range("B" + i).Value
        security_id = Range("C" + i).Value
        shares = Range("E" + i).Value

Obviously the "A" + i is not going to be read as A1 or A2 but I can't figure out how to change it so that it IS read as A1 or A2, etc...any ideas?
 
Old April 13th, 2005, 01:51 PM
Authorized User
 
Join Date: Apr 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out and used variables:

Dim MyColumns_Range As Range
    Set MyColumns_Range = Range(wsData.Cells(1, "A"), wsData.Cells(1, "A").End(xlDown))
    For Each c In MyColumns_Range
        strRangeA = "A" & i
        strRangeB = "B" & i
        strRangeC = "C" & i
        strRangeE = "E" & i

        fund = Range(strRangeA).Value
        trans_type = Range(strRangeB).Value
        security_id = Range(strRangeC).Value
        shares = Range(strRangeE).Value
 
Old April 13th, 2005, 02:02 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Code:
    Set MyColumns_Range = Range(wsData.Cells(1, "A"), wsData.Cells(1, "A").End(xlDown))
        For Each c In MyColumns_Range
            fund = Range("A" & i).Value
            trans_type = Range("B" & i).Value
            security_id = Range("C" & i).Value
            shares = Range("E" & i).Value
            ought to work just fine. (Note the “&” in place of your “+.”)





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL: Count = Count + 1 elayaraja.s XSLT 3 July 18th, 2008 03:21 AM
Looping ssaranam SQL Server 2005 2 April 17th, 2008 01:40 AM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
Looping..? dedex C# 2 January 6th, 2005 11:24 PM





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