Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 February 12th, 2008, 10:30 PM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a variable to reference a cell

Is it possible to reference a cell using a variable in it name

dim var1 as integer
var1=3

listbox1.additem([c var1])

What I'm trying to do is place the contents of cell c3 into a listbox by using a variable in it's call out. This is not exactly what I'm trying to do but it the simplest way I can think to explain it clearly.

Thanks Mike

 
Old March 18th, 2008, 11:17 AM
Registered User
 
Join Date: Mar 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mike,
Have you tried using Cells(row index,col index)

So your code would look like:

dim var1 as integer
var1=3

listbox1.additem([cells(var1, 3)])

----------------

The number 3 is the number of the column.

Sarah :)
 
Old March 24th, 2008, 04:02 PM
Authorized User
 
Join Date: Mar 2008
Posts: 35
Thanks: 0
Thanked 1 Time in 1 Post
Default

Make the variable type long. Row numbers may get well over the integer limit.
Code:
Dim var1 as long
Listbox1.AddItem Range("C" & var1).Value





Similar Threads
Thread Thread Starter Forum Replies Last Post
variable used as cell reference? dabith Excel VBA 3 March 8th, 2014 12:53 AM
Using Match function retrieve cell reference not wapfu Excel VBA 2 December 11th, 2006 05:09 AM
Reference a Cell in a Webtable. Ahrenl Excel VBA 2 May 25th, 2005 11:25 AM
Passing the cell reference to a variable Artist Excel VBA 0 April 14th, 2004 04:34 AM





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