Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Variables in Excel (Cells & columns) - Excel 2003

Morning all,

I have 2 problems:

1) I am looking to define 2 cells. This is because I want to check in these
cells for all blanks and replace with zeros. No problem there. But instead
of putting the usual - range("a1","c14").select I need to put in variables as
the number of columns on this will change.

I can define a row or column and use this as a reference but am having
trouble defining a specific individual cell:

r = ActiveCell.Column
b = Activecell.row

etc....

How would I go about giving a cell a reference so this macro will work no
matter how many columns there are ?


2) After I do this I want to go through each of the relevant columns and do
a filter for all zeros. No problem in doing that if I know how many columns
there are but this is varable so how do I define this ? At present I have as
below:

Selection.AutoFilter field:=r + 1, Criteria1:="0"
Selection.AutoFilter field:=r + 2, Criteria1:="0"
Selection.AutoFilter field:=r + 3, Criteria1:="0"
etc...


This works fine until I get to the point of the final column. After this
obviously an error appears because there are no columns left.

How do I work variable into this ?


Any help I can get would be much appreciated !!

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Variables in Excel (Cells & columns) - Excel 2003

Assuming headings/data in row 1, then last column is:

Lastcolumn = Cells(1, Columns.Count).End(xlToLeft).Column

HTH

"Coppercrutch" wrote:

Morning all,

I have 2 problems:

1) I am looking to define 2 cells. This is because I want to check in these
cells for all blanks and replace with zeros. No problem there. But instead
of putting the usual - range("a1","c14").select I need to put in variables as
the number of columns on this will change.

I can define a row or column and use this as a reference but am having
trouble defining a specific individual cell:

r = ActiveCell.Column
b = Activecell.row

etc....

How would I go about giving a cell a reference so this macro will work no
matter how many columns there are ?


2) After I do this I want to go through each of the relevant columns and do
a filter for all zeros. No problem in doing that if I know how many columns
there are but this is varable so how do I define this ? At present I have as
below:

Selection.AutoFilter field:=r + 1, Criteria1:="0"
Selection.AutoFilter field:=r + 2, Criteria1:="0"
Selection.AutoFilter field:=r + 3, Criteria1:="0"
etc...


This works fine until I get to the point of the final column. After this
obviously an error appears because there are no columns left.

How do I work variable into this ?


Any help I can get would be much appreciated !!

Thanks in advance

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Columns A, B, C , D & E won't unhide in Excel 2003 Virtual PA Solutions Excel Discussion (Misc queries) 1 May 19th 06 10:38 AM
Excel 2003 - Protecting and Hiding Columns Peppermint Excel Discussion (Misc queries) 2 January 19th 06 04:06 PM
filter rows rather than columns in Excel 2003? Lynne Excel Discussion (Misc queries) 4 December 2nd 05 06:47 PM
Columns in excel 2003 Jackie D Excel Worksheet Functions 6 November 10th 05 06:32 PM
How do I count two variables in different columns in excel? Mad-z Excel Worksheet Functions 2 June 20th 05 03:16 PM


All times are GMT +1. The time now is 12:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"