Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Different Ways To Reference Ranges

I need a very short way to refer to single cell ranges in a worksheet. I
have a calculator that I use in VBA and it references cells in many
worksheets. So I want to keep the code as clean as possible. For example,

'this is what I currently do
Sheets("Labor").Range("B4").Value * Sheets("Labor").Range("C6").Value

Is there a shorter way to write this? I think I have seen people use [B4] *
[C6] or something like that, but how can I include the worksheet?

Thanks in Advance!
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Different Ways To Reference Ranges

Try this
Dim ws As Worksheet
Set ws = Worksheets("Labor")

With ws
.Range("C4").Value = _
.Range("B4").Value * .Range("C6").Value
End With

"Ryan H" wrote:

I need a very short way to refer to single cell ranges in a worksheet. I
have a calculator that I use in VBA and it references cells in many
worksheets. So I want to keep the code as clean as possible. For example,

'this is what I currently do
Sheets("Labor").Range("B4").Value * Sheets("Labor").Range("C6").Value

Is there a shorter way to write this? I think I have seen people use [B4] *
[C6] or something like that, but how can I include the worksheet?

Thanks in Advance!
--
Cheers,
Ryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Different Ways To Reference Ranges

You could use:

Worksheets("Sheet1").[a1]
or even
['Sheet 99'!x88]
or if you know the code name for that sheet
Sheet1.[a1]

But it turns out, that the [] notation is slower than the range(...).value
syntax.

Personally, I find the range(...).value easier to read/debug/write--even though
there are more characters that I have to type.

Ryan H wrote:

I need a very short way to refer to single cell ranges in a worksheet. I
have a calculator that I use in VBA and it references cells in many
worksheets. So I want to keep the code as clean as possible. For example,

'this is what I currently do
Sheets("Labor").Range("B4").Value * Sheets("Labor").Range("C6").Value

Is there a shorter way to write this? I think I have seen people use [B4] *
[C6] or something like that, but how can I include the worksheet?

Thanks in Advance!
--
Cheers,
Ryan


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Different Ways To Reference Ranges

Thanks for the replay Dave. Just curious, how do you know it is slower with
the brackets?
--
Cheers,
Ryan


"Dave Peterson" wrote:

You could use:

Worksheets("Sheet1").[a1]
or even
['Sheet 99'!x88]
or if you know the code name for that sheet
Sheet1.[a1]

But it turns out, that the [] notation is slower than the range(...).value
syntax.

Personally, I find the range(...).value easier to read/debug/write--even though
there are more characters that I have to type.

Ryan H wrote:

I need a very short way to refer to single cell ranges in a worksheet. I
have a calculator that I use in VBA and it references cells in many
worksheets. So I want to keep the code as clean as possible. For example,

'this is what I currently do
Sheets("Labor").Range("B4").Value * Sheets("Labor").Range("C6").Value

Is there a shorter way to write this? I think I have seen people use [B4] *
[C6] or something like that, but how can I include the worksheet?

Thanks in Advance!
--
Cheers,
Ryan


--

Dave Peterson
.

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
reference to external ranges eggpap Excel Programming 1 December 23rd 07 12:01 PM
variable reference ranges SC Excel Discussion (Misc queries) 2 September 14th 07 05:18 AM
Named ranges which seem to reference old workbooks/worksheets mhudsonak Excel Discussion (Misc queries) 2 September 11th 06 03:42 PM
Reference Ranges Chris Excel Programming 1 August 15th 06 08:44 PM
How to Variable Reference Row Ranges? VicWestVan Excel Programming 5 July 26th 06 04:50 PM


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