Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ML ML is offline
external usenet poster
 
Posts: 57
Default Selection in a range.

Hi

I am extremely new to Excel programming (this morning) and have had some
macro designs thrust upon me.

I am trying to select rows 1 & 2 of a previous selection (to effectively
format the header rows in table).

I have made it work where the table is 3 columns using:

Selection.Range("A1:C2").Select

but I need to make it work for tables more than 3 colums, the tables could
be any size and anywhere on a worksheet. So I tried:

Selection.Range("1:2").Select

but this didn't work.

Any suggestions?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Selection in a range.

On Mon, 8 Sep 2008 05:00:01 -0700, ML wrote:

Hi

I am extremely new to Excel programming (this morning) and have had some
macro designs thrust upon me.

I am trying to select rows 1 & 2 of a previous selection (to effectively
format the header rows in table).

I have made it work where the table is 3 columns using:

Selection.Range("A1:C2").Select

but I need to make it work for tables more than 3 colums, the tables could
be any size and anywhere on a worksheet. So I tried:

Selection.Range("1:2").Select

but this didn't work.

Any suggestions?


First of all, and importantly, there is no need to "select" the cells within
VBA in order to format them. It is more efficient to just address the cells
directly.

One way to set a variable so as to refer to the first two rows in a previous
selection:

------------------------
Dim c As Range
Set c = Selection
Set c = c.Resize(2)
------------------------

If all the cells are being formatted the same, then perhaps something like:

----------------------
With c
.NumberFormat = "@"
.Font.Bold = True
.Font.Italic = True
.Font.Size = 16
End With
------------------------

--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
ML ML is offline
external usenet poster
 
Posts: 57
Default Selection in a range.

This has solved it.

Many thanks.


"Ron Rosenfeld" wrote:

On Mon, 8 Sep 2008 05:00:01 -0700, ML wrote:

Hi

I am extremely new to Excel programming (this morning) and have had some
macro designs thrust upon me.

I am trying to select rows 1 & 2 of a previous selection (to effectively
format the header rows in table).

I have made it work where the table is 3 columns using:

Selection.Range("A1:C2").Select

but I need to make it work for tables more than 3 colums, the tables could
be any size and anywhere on a worksheet. So I tried:

Selection.Range("1:2").Select

but this didn't work.

Any suggestions?


First of all, and importantly, there is no need to "select" the cells within
VBA in order to format them. It is more efficient to just address the cells
directly.

One way to set a variable so as to refer to the first two rows in a previous
selection:

------------------------
Dim c As Range
Set c = Selection
Set c = c.Resize(2)
------------------------

If all the cells are being formatted the same, then perhaps something like:

----------------------
With c
.NumberFormat = "@"
.Font.Bold = True
.Font.Italic = True
.Font.Size = 16
End With
------------------------

--ron

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Selection in a range.

On Mon, 8 Sep 2008 05:38:00 -0700, ML wrote:

This has solved it.

Many thanks.


Glad to help.

Thanks for the feedback.
--ron
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
Narrow Range based on Selection in Another Range David Excel Discussion (Misc queries) 3 July 1st 07 05:12 PM
Range(Selection, Selection.End(xlToRight)).Select Dave Birley Excel Programming 2 June 6th 07 04:53 PM
Identifying a selection of a selection of a range swimfast Excel Worksheet Functions 1 March 1st 07 02:51 AM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM
Creating range name for a range selection Mervyn Thomas Excel Programming 1 January 26th 04 05:18 PM


All times are GMT +1. The time now is 06:33 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"