PC Review


Reply
Thread Tools Rate Thread

clearing columns in VBA

 
 
=?Utf-8?B?RGF2ZSBG?=
Guest
Posts: n/a
 
      6th Apr 2007
I understand the following clears column A of the active sheet:

Sub ClearColumnTest()
ActiveSheet.Range("A:A").Clear
End Sub

I also understand that this does the same thing:

Sub ClearColumnTest()
ActiveSheet.Columns(1).Clear
End Sub

But when creating formulas in Excel (as opposed to in VBA) we refer to
column 1 as column A. Why the discrepancy?

Is this a holdover from the R1C1 reference style of Lotus?

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.
 
Reply With Quote
 
 
 
 
matt
Guest
Posts: n/a
 
      6th Apr 2007
On Apr 6, 7:38 am, Dave F <D...@discussions.microsoft.com> wrote:
> I understand the following clears column A of the active sheet:
>
> Sub ClearColumnTest()
> ActiveSheet.Range("A:A").Clear
> End Sub
>
> I also understand that this does the same thing:
>
> Sub ClearColumnTest()
> ActiveSheet.Columns(1).Clear
> End Sub
>
> But when creating formulas in Excel (as opposed to in VBA) we refer to
> column 1 as column A. Why the discrepancy?
>
> Is this a holdover from the R1C1 reference style of Lotus?
>
> Dave
> --
> A hint to posters: Specific, detailed questions are more likely to be
> answered than questions that provide no detail about your problem.


Dave,

The computer would probably prefer to handle row, column index numbers
rather than letters; however, you can create formulas in VBA using A1
notation. I don't know that there is a "discrepancy" because you can
execute code with numbers or letters. I wouldn't say that it is a
"discrepancy," I would say that it is flexibility.

For example, the following syntax will execute:
Range("a3").Formula = "=SUM(A1:A2)"

I hope this answers your question.

Matt

 
Reply With Quote
 
=?Utf-8?B?QXJ0?=
Guest
Posts: n/a
 
      6th Apr 2007
Dave,

On the VBA side I think it's there to make it easier for loops and using
other variables as the row or column indicators. On the Sheet side I think
it's more readable with the "A" notation. Just my opinion.



"Dave F" wrote:

> I understand the following clears column A of the active sheet:
>
> Sub ClearColumnTest()
> ActiveSheet.Range("A:A").Clear
> End Sub
>
> I also understand that this does the same thing:
>
> Sub ClearColumnTest()
> ActiveSheet.Columns(1).Clear
> End Sub
>
> But when creating formulas in Excel (as opposed to in VBA) we refer to
> column 1 as column A. Why the discrepancy?
>
> Is this a holdover from the R1C1 reference style of Lotus?
>
> Dave
> --
> A hint to posters: Specific, detailed questions are more likely to be
> answered than questions that provide no detail about your problem.

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      6th Apr 2007
Excel and VBA are two different software entities, but VBA is compatible with
Excel as a macro and programming language. In VBA when writing code and
referring to collections like Sheets, Columns and Rows, it is more efficient
to use index numbers (i.e. 1, 2, 3, etc.) that usinging full range references
or names. The software developers built this flexibility into the product in
many cases based on feedback from users. There are only a few things that
are in Excel to accomodate Lotus123.

"Dave F" wrote:

> I understand the following clears column A of the active sheet:
>
> Sub ClearColumnTest()
> ActiveSheet.Range("A:A").Clear
> End Sub
>
> I also understand that this does the same thing:
>
> Sub ClearColumnTest()
> ActiveSheet.Columns(1).Clear
> End Sub
>
> But when creating formulas in Excel (as opposed to in VBA) we refer to
> column 1 as column A. Why the discrepancy?
>
> Is this a holdover from the R1C1 reference style of Lotus?
>
> Dave
> --
> A hint to posters: Specific, detailed questions are more likely to be
> answered than questions that provide no detail about your problem.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      6th Apr 2007
But these work, too:

Option Explicit
Sub ClearColumnTest()
ActiveSheet.Columns("A").Clear
ActiveSheet.Columns("C:C").Clear
End Sub

IIRC, the first may cause problems in some earlier versions of excel.

And it's more than a hold over. I'm guessing that it allows some flexibility
for the user. (There are people who actually like R1C1 reference style!)

You can use: Tools|Options|General|check R1C1 Reference style
and write all your formulas using column numbers:

=r3c5
or
=r[-1]c[7]

====
My personal preference is to use:
ActiveSheet.Range("A:A").Clear
or
ActiveSheet.Range("A1").entirecolumn.Clear

Then I can change it to:
ActiveSheet.Range("A:C,d,g:H").Clear

without swearing when I do:
ActiveSheet.Columns("A:C,d,g:H").Clear




Dave F wrote:
>
> I understand the following clears column A of the active sheet:
>
> Sub ClearColumnTest()
> ActiveSheet.Range("A:A").Clear
> End Sub
>
> I also understand that this does the same thing:
>
> Sub ClearColumnTest()
> ActiveSheet.Columns(1).Clear
> End Sub
>
> But when creating formulas in Excel (as opposed to in VBA) we refer to
> column 1 as column A. Why the discrepancy?
>
> Is this a holdover from the R1C1 reference style of Lotus?
>
> Dave
> --
> A hint to posters: Specific, detailed questions are more likely to be
> answered than questions that provide no detail about your problem.


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing cells without clearing formulas marsjune68 Microsoft Excel Misc 2 10th Apr 2009 07:39 PM
Clearing out blank rows/columns =?Utf-8?B?U3RldmVEQjE=?= Microsoft Excel Worksheet Functions 3 18th Oct 2007 11:25 PM
Clearing information in certain columns =?Utf-8?B?am9sbHlfbG9sbHk=?= Microsoft Excel Misc 1 22nd Apr 2005 02:41 AM
Clearing row and columns Rockee052 Microsoft Excel Programming 2 27th Jan 2004 08:34 AM
Xcel or Access sort columns of names so that I remove the intersect between 2 columns from one of the columns? William.R.Reisen Microsoft Access External Data 2 20th Dec 2003 02:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 PM.