excel help
 

MegaSack DRAW - This year's winner is user - rgwb
We will be in touch

[Closed] excel help

7 Posts
3 Users
0 Reactions
54 Views
 mrmo
Posts: 10710
Free Member
Topic starter
 

VBA bit,

Range("A3:I256")

This works fine when the pivot table has a data source of A3 to I256, problem is how do i get this to change.

i have used rows.count to populate a variable and find the end of the data not sure how i can change the 256 to be rows.count.

anyone help.

What is the correct syntax.


 
Posted : 06/04/2009 1:10 pm
Posts: 36
Free Member
 

use offset to give you a variable range.


 
Posted : 06/04/2009 1:13 pm
 mrmo
Posts: 10710
Free Member
Topic starter
 

managed to get it to work, create a text variable, and concatenate the text/variable to create the range variable.

Seems to work.


 
Posted : 06/04/2009 1:21 pm
Posts: 36
Free Member
 

using "indirect?"


 
Posted : 06/04/2009 1:23 pm
Posts: 0
Free Member
 

I find that instead of using a string for the Range reference it's easier to use cells eg; this code colours cells A1:J1 in yellow, you can easily use any integer count to modify the range through the Cells(rows,columns)

[code]
Public Sub tester()
Dim myRange As Range
Set myRange = ActiveWorkbook.ActiveSheet.Range(Cells(1, 1), Cells(1, 10))
myRange.Interior.ColorIndex = 6
End Sub
[/code]


 
Posted : 06/04/2009 1:37 pm
 mrmo
Posts: 10710
Free Member
Topic starter
 

rowsfd = Worksheets("FD").UsedRange.rows.Count
j = "Z" & rowsfd
pivotfd = "A3:" & j
Range(pivotfd).Select


 
Posted : 06/04/2009 1:51 pm
 mrmo
Posts: 10710
Free Member
Topic starter
 

Next query

I am trying to create a pivot table. This doesn't work, but if i define a named range in Excel and use that as the range for sourcedata it works. So how am i using Sourcedata incorrectly?

Sub pivotroof()
Dim PC As PivotCache
Dim PT As PivotTable
Set flooringdata = Worksheets("FD").Range("a3:z100")
Set PC = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=(flooringdata))
Set PT = ActiveSheet.PivotTables.Add(PivotCache:=PC, Tabledestination:="")


 
Posted : 06/04/2009 3:22 pm
Posts: 0
Free Member
 

I think that the sourcedata variable is string only so just use the "FD!A3:Z100" string instead


 
Posted : 07/04/2009 9:56 am