p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Microsoft Office > Excel VBA > Excel VBA
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 20th, 2007, 10:25 AM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default varying data range

Hi,

I have a workbook with 1 sheet that contains data and 7 sheets that have pivot tables building off of the data from the first sheet. This data gets imported in daily and varies in range. I use workbook.refreshall to run the fresh data through the pivot tables.

How can I set up the pivot tables to get all the data from the 1st sheet regardless of what the range is?

Thanks,
David

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 22nd, 2007, 08:58 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use a dynamic range name for the pivot table data range. The general formula is;
=OFFSET(SheetName!$A:$1,0,0,COUNTA(SheetName!$A:$A ),COUNTA(SheetName!$1:$1))
A1 is the first cell of the data range.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 24th, 2007, 02:55 PM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks FullSquat! that worked great.
Now, One more thing I'm having trouble with. I have a couple of formulas that go along with the data I'm bringing in. They are in columns beside the data. I need for the formulas to "drag down" with the rows of data...i.e. J3x4,J4x4,J5x4,J6x4.....The formula is the same it just changes w/ the row number. How can I do this?

thanks,
David

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 25th, 2007, 02:16 AM
Registered User
 
Join Date: Jul 2007
Location: winchester, calafornia, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I dont understand whats wrong.
i did f1*4 and i dragged it down and it workes fine.
= f2*4 f5*4 and so on...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old July 25th, 2007, 01:41 PM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want it to be automated w/ vba, so when new data is imported in the formula it will drag down with the new data and stop at the last row of data.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old July 25th, 2007, 01:48 PM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I've almost got it working like I want.
I put this code in a module:
Code:
Function LastCell(ws As Worksheet) As Range
  Dim LastRow&, LastCol%
  On Error Resume Next

  With ws
    LastRow& = .Cells.Find(What:="*", SearchDirection:=xlPrevious, _
      SearchOrder:=xlByRows).Row
    LastCol% = .Cells.Find(What:="*", _
      SearchDirection:=xlPrevious, _
      SearchOrder:=xlByColumns).Column
  End With
  Set LastCell = ws.Cells(LastRow&, LastCol%)
End Function
Then I call that function from the macro I created, like so:
Code:
Dim sLast As String
sLast = LastCell(Sheet1).Row

    Range("X2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-16]=""0247"",""W"",LEFT(RC[ 18],1))"
    Selection.AutoFill Destination:=Range("X2:X" + sLast), Type:=xlFillDefault
    Range("X2:X" + sLast).Select
    ActiveWindow.ScrollRow = 2

The only thing now is that sLast is getting a value of 11 every time and I haven't been able to figure out why yet. There are about 8,000 rows of data, so 11 is a tad off.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old July 27th, 2007, 03:30 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is a suggestion. Select a column with continuous data and use VBA code similar to the following:

    Dim WS As Worksheet
    Dim Rcell As Range

    Set WS = Sheets("SheetName")
    Set Rcell = WS.Range("A2") 'First cell of data


    Do Until IsEmpty(Rcell.Value) 'Stops at last cell in the column

        'Enter Formula in offset columns

        Rcell.Offset(0, 3).FormulaR1C1 = "=45*RC[-2]"

        'Moves Rcell to the next row

   Set Rcell = Rcell.Offset(1, 0)

    Loop


The program will enter the formula in the column offset to the right as specified in the Offset method, move down the column to the next row and stop at the last row in the column.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Access data whith varying columns dbellavi SQL Server DTS 15 January 30th, 2008 06:23 AM
Counting Number of Rows Between Data Range eusanpe Excel VBA 6 September 21st, 2006 08:17 AM
Display data within data range? ktsis ASP.NET 1.0 and 1.1 Basics 2 June 9th, 2006 04:06 PM
Return Data from Excel 97 Range into table interrupt Javascript How-To 3 March 4th, 2005 07:14 AM
External Data Range Properties ioates Excel VBA 1 December 3rd, 2004 08:03 AM



All times are GMT -4. The time now is 02:05 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc