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 December 27th, 2007, 04:15 PM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Finding Column Range

I created a macro to add three vlookup functions to three new columns within the sheet. The vlookup is dependant on the first column of the sheet's row data, which is already populated prior to applying the macro. I want the new columns created to only create the amount of rows contained within the first row of the sheet. I was thinking of making a function similiar to an end of file loop.

if row.text is not empty
then row + 1
else exit

Something simple like that, there will never be empty rows in the first column besides when it reaches the end of its data.

I'm sorry if i'm wording this incorrectly, but i used pseudo code so that i clearly get my idea accross.

Thanks in advance for any help provided.

Noc
 
Old December 27th, 2007, 08:57 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Assuming that you need the last 'filled' row :

Set SHT = ActiveSheet

 lRow = SHT.RANGE("A:A").SpecialCells(xlCellTypeLastCell). Row
 For i = 1 To lRow

   ' Your code for VLookup can go here

 Next i

Cheers
Shasur


http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old December 28th, 2007, 05:10 PM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou very much for your help, I am new to vba excel code and want to learn more.

What does the following syntax represent:

SpecialCells(xlCellTypeLastCell).

Is there more pre-defined functions in accordance with special cells?
Is 'xl' another specific excel vba code syntax?
And is CellTypeLastCell contained within that syntax?

I'm sure there is a common area to learn this, if you could point me in that direction I can read up and figure out the stuff on my own.
 
Old December 29th, 2007, 11:36 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

First let me explain your questions

Is there more pre-defined functions in accordance with special cells?

  Yes SpecialCElls is a predefined method - There are many type of special cells, like the cells that have formula, cells that have comments etc. Excel Identifies this and returns a range (where they are found) in this method

Is 'xl' another specific excel vba code syntax?

And is CellTypeLastCell contained within that syntax?

The xl prefix is for easy use. Usually there are many constants that are used as input for the specialcells method - The compiler recognizes this by enumerated numbers (0,1,2..). But for the benefit of programmers they are denoted by constants like the following

xlCellTypeAllFormatConditions
xlCellTypeAllValidation
xlCellTypeBlanks
xlCellTypeComments
xlCellTypeConstants
xlCellTypeFormulas
xlCellTypeLastCell
xlCellTypeSameFormatConditions
xlCellTypeSameValidation
xlCellTypeVisible

Now you need not worry if you need to use 3 or 6 or 0 for getting the last cell isn't it .. you will use xlCellTypeLastCell .. simple right!

Here is the VBA Reference that might be useful to you (http://www.microsoft.com/downloads/d...displaylang=en)

Also browse msdn.microsoft.com for getting more updates on Excel VBA

Welcome to VBA:)

Cheers
Shasur


http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding nday of evry month within date range arnabghosh Classic ASP Professional 0 December 6th, 2007 01:42 AM
Out of range values stored in tinyint column BorisG SQL Server 2005 7 July 14th, 2007 12:34 PM
Finding Column Name prabhakaran SQL Server 2000 3 December 4th, 2006 09:36 AM
finding and populating next available column rlrigsby Excel VBA 0 April 14th, 2006 04:08 PM
find name and define range for Column qball Excel VBA 4 November 17th, 2004 03:55 PM





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