+ Reply to Thread
Results 1 to 9 of 9

Migrated Code Error

  1. #1
    Registered User
    Join Date
    11-24-2008
    Location
    Atlanta
    Posts
    11

    Migrated Code Error

    Does anyone know why I get an error when I migrated this code over to a new worksheet from an old one, even though the tables remained the same size?

    Dim x As Long, lastCell As Range, LR As Long, LC As Long, i As Integer, ColSum As Long, fc As Long
    x = ActiveSheet.UsedRange.Columns.Count
    i = 2
    For i = 3 To LC
    ColSum = (Cells(1, i).ColumnWidth + Cells(1, i - 1).ColumnWidth)
    Next i
    Set lastCell = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0)
    LR = lastCell.Row

    Do Until Application.Count(Range(Cells(LR, 2), Cells(LR, 256))) <> 0
    Set lastCell = lastCell.Offset(-1, 0)
    LR = lastCell.Row
    LC = lastCell.Column

  2. #2
    Registered User
    Join Date
    11-24-2008
    Location
    Atlanta
    Posts
    11
    Sorry, the error shows up on this line:

    Set lastCell = lastCell.Offset(-1, 0)

  3. #3
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Hi,

    if your cursor is one first row..

    the the above command will generate error because lastCell.Offset(-1, 0) is referencing row before the first row....

  4. #4
    Registered User
    Join Date
    11-24-2008
    Location
    Atlanta
    Posts
    11
    Hrm.. I'm not sure if I understand what you're saying, but it didn't seem to have an effect. And again, this runs on another worksheet but not when I migrate it over.

  5. #5
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Trying

    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.
    Last edited by Shijesh Kumar; 12-04-2008 at 12:09 PM.

  6. #6
    Registered User
    Join Date
    11-24-2008
    Location
    Atlanta
    Posts
    11
    didn't work. thanks for the suggestion though.

  7. #7
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Can you post ur workbook so that we can check wheres the error

  8. #8
    Registered User
    Join Date
    11-24-2008
    Location
    Atlanta
    Posts
    11
    i've attached the worksheet and here's the full code:

    '
    ' PrintSetup Macro
    '
    Dim x As Long, lastCell As Range, LR As Long, LC As Long, i As Integer, ColSum As Long, fc As Long
    x = ActiveSheet.UsedRange.Columns.Count
    i = 2
    For i = 3 To LC
    ColSum = (Cells(1, i).ColumnWidth + Cells(1, i - 1).ColumnWidth)
    Next i
    Set lastCell = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0)
    LR = lastCell.Row

    Do Until Application.Count(Range(Cells(LR, 2), Cells(LR, 256))) <> 0
    Set lastCell = lastCell.Offset(-1, 0)
    LR = lastCell.Row
    LC = lastCell.Column

    ActiveSheet.PageSetup.CenterHeader = Cells(1, 3) & Chr(13) & Cells(2, 3)
    ActiveSheet.PageSetup.CenterFooter = Cells(3, 3)

    'colppg = colsum/9
    'foursppg = int(colppg/4)
    'inc = foursppg*4

    Loop
    ActiveSheet.PageSetup.PrintArea = Range(Cells(5, 2), lastCell).Address

    For i = 8 To LC Step 6
    Worksheets("Sheet1").Columns(i + 1).PageBreak = xlPageBreakManual
    Next i

    With ActiveSheet.PageSetup
    .Orientation = xlLandscape
    .PaperSize = xlPaperLetter
    End With

    End Sub

    thanks again
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-24-2008
    Location
    Atlanta
    Posts
    11
    ah it works! i changed the <> to = on the Do Until line. Funny that the <> works with the pivot table but = works for a normal excel table. any insight on that?

+ 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