Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default How do I create this range?

I am trying to set a range in vba, but am having trouble figuring out how to
code it.
I know the proper syntax is normally this:
MyRange = Worksheets(ActSheet).Range("C5:C50")

My problem is that I won't have the LETTER (like C) of the column, only the
number, like instead of column "C" I would have a number 3. So basically,
how can I replace the ("C5:C50") portion with integer type variables?

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default How do I create this range?

One way:

Dim MyRange As Variant
Dim nCol As Long
nCol = 3
MyRange = Worksheets(ActSheet).Cells(5, nCol).Resize(46, 1).Value

In article ,
monica wrote:

I am trying to set a range in vba, but am having trouble figuring out how to
code it.
I know the proper syntax is normally this:
MyRange = Worksheets(ActSheet).Range("C5:C50")

My problem is that I won't have the LETTER (like C) of the column, only the
number, like instead of column "C" I would have a number 3. So basically,
how can I replace the ("C5:C50") portion with integer type variables?

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default How do I create this range?

Great, that works. Now how can I do a sum on the contents of that range? I
tried doing "for each cell in MyRange" but it gives an error...

Thanks again.


"JE McGimpsey" wrote:

One way:

Dim MyRange As Variant
Dim nCol As Long
nCol = 3
MyRange = Worksheets(ActSheet).Cells(5, nCol).Resize(46, 1).Value

In article ,
monica wrote:

I am trying to set a range in vba, but am having trouble figuring out how to
code it.
I know the proper syntax is normally this:
MyRange = Worksheets(ActSheet).Range("C5:C50")

My problem is that I won't have the LETTER (like C) of the column, only the
number, like instead of column "C" I would have a number 3. So basically,
how can I replace the ("C5:C50") portion with integer type variables?

Thanks in advance


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default How do I create this range?

Oops, nevermind...I figured it out!

"monica" wrote:

Great, that works. Now how can I do a sum on the contents of that range? I
tried doing "for each cell in MyRange" but it gives an error...

Thanks again.


"JE McGimpsey" wrote:

One way:

Dim MyRange As Variant
Dim nCol As Long
nCol = 3
MyRange = Worksheets(ActSheet).Cells(5, nCol).Resize(46, 1).Value

In article ,
monica wrote:

I am trying to set a range in vba, but am having trouble figuring out how to
code it.
I know the proper syntax is normally this:
MyRange = Worksheets(ActSheet).Range("C5:C50")

My problem is that I won't have the LETTER (like C) of the column, only the
number, like instead of column "C" I would have a number 3. So basically,
how can I replace the ("C5:C50") portion with integer type variables?

Thanks in advance


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default How do I create this range?

You need to do

Set MyRange = (whatever)

otherwise you'll just get the Value of the Range on the
right-hand side, not the Range object itself. You could
also use:

Dim MyRange as Range

instead of ..as Variant, which would catch this kind of error.



monica wrote:
Great, that works. Now how can I do a sum on the contents of that range? I
tried doing "for each cell in MyRange" but it gives an error...

Thanks again.


"JE McGimpsey" wrote:

One way:

Dim MyRange As Variant
Dim nCol As Long
nCol = 3
MyRange = Worksheets(ActSheet).Cells(5, nCol).Resize(46, 1).Value

In article ,
monica wrote:

I am trying to set a range in vba, but am having trouble figuring out how to
code it.
I know the proper syntax is normally this:
MyRange = Worksheets(ActSheet).Range("C5:C50")

My problem is that I won't have the LETTER (like C) of the column, only the
number, like instead of column "C" I would have a number 3. So basically,
how can I replace the ("C5:C50") portion with integer type variables?

Thanks in advance





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default How do I create this range?

Now how can I do a sum on the contents of that range?
I tried doing "for each cell in MyRange" ....


Don't know if this idea will help...

Const C As Long = 3
Debug.Print _
WorksheetFunction.Sum(Range(Cells(5, C), Cells(50, C)))

--
HTH. :)
Dana DeLouis
Windows XP, Office 2003


"monica" wrote in message
...
Oops, nevermind...I figured it out!

"monica" wrote:

Great, that works. Now how can I do a sum on the contents of that range?
I
tried doing "for each cell in MyRange" but it gives an error...

Thanks again.


"JE McGimpsey" wrote:

One way:

Dim MyRange As Variant
Dim nCol As Long
nCol = 3
MyRange = Worksheets(ActSheet).Cells(5, nCol).Resize(46, 1).Value

In article ,
monica wrote:

I am trying to set a range in vba, but am having trouble figuring out
how to
code it.
I know the proper syntax is normally this:
MyRange = Worksheets(ActSheet).Range("C5:C50")

My problem is that I won't have the LETTER (like C) of the column,
only the
number, like instead of column "C" I would have a number 3. So
basically,
how can I replace the ("C5:C50") portion with integer type variables?

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
create range bar graph Aussie1497 Charts and Charting in Excel 2 April 26th 23 11:47 AM
How do I create a Range Name? Curious New Users to Excel 7 December 14th 07 09:13 PM
Trying to create a range in an IF function dmorgenstern Excel Worksheet Functions 2 March 6th 06 07:26 PM
Create/copy combo boxes in one range if condition is met in a different range LB[_4_] Excel Programming 4 September 30th 05 12:21 AM
create a chart without set range Noemi Excel Programming 4 September 26th 05 02:53 AM


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

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

About Us

"It's about Microsoft Excel"