+ Reply to Thread
Results 1 to 2 of 2

Count number of columns and return an Alphabetic character?!

Hybrid View

  1. #1
    Registered User
    Join Date
    03-19-2009
    Location
    Arnhem, Holland
    MS-Off Ver
    Excel 2003
    Posts
    35

    Count number of columns and return an Alphabetic character?!

    To be more specific: I want to have the position of my last column and row in a certain pivot table. When there are more columns than rows...than I need a xlLandscape pagesetup, else I need a slPortrait pagesetup.

    I can do this:

    Select the range of the generated pivot...
    Application.ScreenUpdating = False
    Dim myLastRow As Long
    Dim myLastColumn As Long
    Range("A1").Select
        myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
        myLastColumn = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
        myLastCell = Cells(myLastRow, myLastColumn).Address
    myrange = "a1:" & myLastCell
    Application.ScreenUpdating = True
    Range(myrange).Select
    then I can do this:

    I determine the number of columns....(and rows, but dont need those)
    Dim iColumnCount As Integer
        Dim lRowCount As Long
        iColumnCount = ActiveSheet.UsedRange.Columns.Count
        lRowCount = ActiveSheet.UsedRange.Rows.Count
    At this moment I know this: Number of columns = 14. and rows are 12

    Good!

    But then my code fails. I'm not able to do:

    If ColumnCount < lRowCount then
         ActiveSheet.PageSetup.Orientation = xlLandscape
    Else: ....etc...

    Can somebody help me out? pls?
    Last edited by Wino; 04-29-2009 at 08:00 AM. Reason: solved

  2. #2
    Registered User
    Join Date
    03-19-2009
    Location
    Arnhem, Holland
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Count number of columns and return an Alphabetic character?!

    Murphy's law: I found my own solution.

    The last section in the following code gives the solution:

    Application.ScreenUpdating = False
    Dim myLastRow As Long
    Dim myLastColumn As Long
    Range("A1").Select
        myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
        myLastColumn = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
        myLastCell = Cells(myLastRow, myLastColumn).Address
    myrange = "a1:" & myLastCell
    Application.ScreenUpdating = True
    Range(myrange).Select
           
        Range("M1").Activate
        ActiveSheet.PageSetup.PrintArea = myrange
        With ActiveSheet.PageSetup
            .PrintTitleRows = "$3:$4"
            .PrintTitleColumns = ""
        End With
        ActiveSheet.PageSetup.PrintArea = myrange
        Range(myrange).Select
          
        If myLastRow < 20 Then
        ActiveSheet.PageSetup.Orientation = xlLandscape
        Else: ActiveSheet.PageSetup.Orientation = xlPortrait
        End If

+ 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