+ Reply to Thread
Results 1 to 7 of 7

Newbie with problem (duh!)

  1. #1
    Registered User
    Join Date
    07-03-2006
    Posts
    74

    Newbie with problem (duh!)

    Hi Guys & Gals,

    Why doesn't this work?

    ActiveSheet.PageSetup.PrintArea = "$a$1:$z$"&CEILING(COUNTA(D3:D42)/8;1)*46

    This is only one line of a macro and the problem lies in the range-defining part. I'm totally new to VB, so the problem's gotta be in the syntax...

    Thanks for any feedback

  2. #2
    Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    267
    Hi

    Is that some kind of fromula on the end?

    seting a print area should look llike this

    ActiveSheet.PageSetup.PrintArea = "$C$5:$J$24"

    In your code

    ActiveSheet.PageSetup.PrintArea = "$a$1:$z$"&CEILING(COUNTA(D3:D42)/8;1)*46

    You seem to have somekind of formula on the end

    Hope it helps
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  3. #3
    Forum Contributor starryknight64's Avatar
    Join Date
    09-27-2006
    Location
    Missouri
    MS-Off Ver
    2003 (Work) & 2007 (Home)
    Posts
    193
    Get rid of the semi-colon and replace it with a comma.
    starryknight64

  4. #4
    Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    267
    or thinking about it, as i have never seen anything after the range when setting a print area but try:

    ActiveSheet.PageSetup.PrintArea = "$a$1:$z$" & "CEILING(COUNTA(D3:D42)/8:1)*46"

  5. #5
    Forum Contributor starryknight64's Avatar
    Join Date
    09-27-2006
    Location
    Missouri
    MS-Off Ver
    2003 (Work) & 2007 (Home)
    Posts
    193
    ActiveSheet.PageSetup.PrintArea = "$a$1:$z$"&CEILING(COUNTA(D3:D42)/8,1)*46
    Here's what he's doing:

    Since CEILING(COUNTA(D3:D42)/8,1)*46 returns a number, he's concatenating it to the end of the string "$a$1:$z$" (which is missing a number from the end of it).

    Thus, making his print area dynamic to his spreadsheet.

    Say, for example, CEILING(COUNTA(D3:D42)/8,1)*46 = 5.
    Then, ActiveSheet.PageSetup.PrintArea = "$a$1:$z$5"
    Last edited by starryknight64; 10-05-2006 at 09:58 AM.

  6. #6
    Registered User
    Join Date
    07-03-2006
    Posts
    74
    Yes, it's a formula. It checks how many fields have values in them on one worksheet, and for every 8 values it should increase the printarea on another worksheet by 46 rows.
    So, the formula looks for the number of values in (d3:d42) and divides by 8 and rounds up to the nearest integer to get the multiplier, so that the printarea would be :

    for 8 values : $a$1:$z$46
    for 16 values : $a$1:$z$92
    for 24 values : $a$1:$z$138

    Since the printarea in the VB line is between "", I thought it regarded it as text, so I substituted the rownumber by my formula, as you would in an INDIRECT-formula...

    I also realise now I should have "pointed" to the other worksheet, because now it doesn't know it has to look there for the values...

    This is the original macro, that I "connected" to a button :

    Sub Print_Click()

    Sheets("Page1").Select
    Range("A1:Z46").Select
    ActiveSheet.PageSetup.PrintArea = "$a$1:$z$46"
    ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
    :=True

    End Sub

  7. #7
    Registered User
    Join Date
    07-03-2006
    Posts
    74
    Ok, tried something different :

    Private Sub CommandButton1_Click()
    Dim MyValue As Integer
    Sheets("Blad1").Select
    MyValue = Range("ab1").Value
    Range("$A$1:$Z$" & MyValue).Select
    ActiveSheet.PageSetup.PrintArea = "$A$1:$Z$" & MyValue
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    Sheets("Registers").Select
    End Sub

    So I let the spreadsheet take care of the formula in cell AB1, which returns an integer, i.e. multiples of 46. The button is placed on sheet "Register", what has to be printed is located on sheet "Blad1". As I see it, all this is pretty straightforward... So why does it give me an error in line "Range("$A$1:$Z$" & MyValue).Select"? For a value of 46 in AB1, this should return "Range("$A$1:$Z$46"), no?

    Thanks for any feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1