Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 11
Default Adding a variable into a range declaration

Here is my defined variable:

Dim RowCount As Long, myRange As Range
Set myRange = Columns("A:A")
RowCount = Application.WorksheetFunction.CountA(myRange)

I am trying to apply the RowCount variable in two situations:

a) copying a formula down the entire length of column B to last row:

Range("B8").Select
ActiveCell.FormulaR1C1 = "The details of my formula"
Range("B8").Select
Selection.Copy
Range("B9:B1000").Select
ActiveSheet.Paste

I'm trying to replace B1000 with a reference to the variable RowCount.
I've tried... Range("B9:B(RowCount)").Select ... and it doesn't work.

b) creating a new pivot table:

Range("A7:BB1000").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Raw Data'!R7C1:R1000C54").CreatePivotTable TableDestination:="", TableName _
:="PivotTable1", DefaultVersion:=xlPivotTableVersion10

I'm trying to replace "A7:BB1000" and "R7C1:R1000C54" with their VB counter-part that references the variable RowCount.

Somehow I'm thinking that I'm looking right past the obvious. :(

Please help me figure this out...
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Adding a variable into a range declaration

a)

Range("B8:b" & rowcount).formula = "The details of my formula"

b)

Range("A7:BB" & rowcount).Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Raw Data'!R7C1:R" & rowcount & "C54").CreatePivotTable
TableDestination:="", TableName _
:="PivotTable1", DefaultVersion:=xlPivotTableVersion10


Malvaro wrote:

Here is my defined variable:

Dim RowCount As Long, myRange As Range
Set myRange = Columns("A:A")
RowCount = Application.WorksheetFunction.CountA(myRange)

I am trying to apply the RowCount variable in two situations:

a) copying a formula down the entire length of column B to last row:

Range("B8").Select
ActiveCell.FormulaR1C1 = "The details of my formula"
Range("B8").Select
Selection.Copy
Range("B9:B1000").Select
ActiveSheet.Paste

I'm trying to replace B1000 with a reference to the variable RowCount.
I've tried... Range("B9:B(RowCount)").Select ... and it doesn't work.

b) creating a new pivot table:

Range("A7:BB1000").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
_
"'Raw Data'!R7C1:R1000C54").CreatePivotTable
TableDestination:="", TableName _
:="PivotTable1", DefaultVersion:=xlPivotTableVersion10

I'm trying to replace "A7:BB1000" and "R7C1:R1000C54" with their VB
counter-part that references the variable RowCount.

Somehow I'm thinking that I'm looking right past the obvious. :(

Please help me figure this out...

--
Malvaro


--

Dave Peterson
  #3   Report Post  
Junior Member
 
Posts: 11
Default

Thanks for all your help!!! :)

Quote:
Originally Posted by Dave Peterson View Post
a)

Range("B8:b" & rowcount).formula = "The details of my formula"

b)

Range("A7:BB" & rowcount).Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Raw Data'!R7C1:R" & rowcount & "C54").CreatePivotTable
TableDestination:="", TableName _
:="PivotTable1", DefaultVersion:=xlPivotTableVersion10

--

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
Adding new variable Raj Excel Discussion (Misc queries) 1 May 5th 08 09:36 PM
VBA - variable declaration Jeff Excel Discussion (Misc queries) 3 January 9th 08 12:45 PM
Adding variable number of blanks ringnab Excel Discussion (Misc queries) 2 July 12th 06 09:29 PM
Adding 3 variable formula to a cell kssflmail Excel Worksheet Functions 3 February 20th 06 05:11 PM
adding variable number of columns confused Excel Worksheet Functions 5 September 23rd 05 10:09 AM


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