+ Reply to Thread
Results 1 to 6 of 6

Runtime Error 1004 on selecting range

  1. #1
    MaltzMD
    Guest

    Runtime Error 1004 on selecting range

    I have a workbookwith 84 sheets. When I try to select (or activate) a range I
    get runtime error 1004. In debugging the file, I find I can print the
    individual cells (in a different workbook, wkFix), but cannot select the
    range. Here's the relevant code:

    With wkState.Sheets("NDX1")
    For j = iCol1 To iCol2
    wkFix.Sheets(1).Cells(j - iCol1 + 1, 13) = .Cells(jRow, j)
    Next j

    ' I have no problem in printing

    Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select

    'But the above line gives me the runtime error

    End With

    Can this have anything to do with the number of spreadsheets?

    I'm running VBA 6.3, Excel 2003 SP1 with XP Pro

    TIA,
    Mike


  2. #2
    Tom Ogilvy
    Guest

    Re: Runtime Error 1004 on selecting range

    is jRow initialized?

    --
    Regards,
    Tom Ogilvy



    "MaltzMD" <[email protected]> wrote in message
    news:[email protected]...
    > I have a workbookwith 84 sheets. When I try to select (or activate) a

    range I
    > get runtime error 1004. In debugging the file, I find I can print the
    > individual cells (in a different workbook, wkFix), but cannot select the
    > range. Here's the relevant code:
    >
    > With wkState.Sheets("NDX1")
    > For j = iCol1 To iCol2
    > wkFix.Sheets(1).Cells(j - iCol1 + 1, 13) = .Cells(jRow, j)
    > Next j
    >
    > ' I have no problem in printing
    >
    > Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select
    >
    > 'But the above line gives me the runtime error
    >
    > End With
    >
    > Can this have anything to do with the number of spreadsheets?
    >
    > I'm running VBA 6.3, Excel 2003 SP1 with XP Pro
    >
    > TIA,
    > Mike
    >




  3. #3
    MaltzMD
    Guest

    Re: Runtime Error 1004 on selecting range

    Yes -- jRow is a known quantity, as are iCol1 & iCol2. The printout confirms
    that they are correct.

    Mike Maltz

    "Tom Ogilvy" wrote:

    > is jRow initialized?
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    > "MaltzMD" <[email protected]> wrote in message
    > news:[email protected]...
    > > I have a workbookwith 84 sheets. When I try to select (or activate) a

    > range I
    > > get runtime error 1004. In debugging the file, I find I can print the
    > > individual cells (in a different workbook, wkFix), but cannot select the
    > > range. Here's the relevant code:
    > >
    > > With wkState.Sheets("NDX1")
    > > For j = iCol1 To iCol2
    > > wkFix.Sheets(1).Cells(j - iCol1 + 1, 13) = .Cells(jRow, j)
    > > Next j
    > >
    > > ' I have no problem in printing
    > >
    > > Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select
    > >
    > > 'But the above line gives me the runtime error
    > >
    > > End With
    > >
    > > Can this have anything to do with the number of spreadsheets?
    > >
    > > I'm running VBA 6.3, Excel 2003 SP1 with XP Pro
    > >
    > > TIA,
    > > Mike
    > >

    >
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    Re: Runtime Error 1004 on selecting range

    Sub ABCD()
    icol1 = 5
    icol2 = 15
    jrow = 3
    Set wkState = Workbooks("Book1")
    Set wkFix = Workbooks("Book2")
    With wkState.Sheets("NDX1")
    For j = icol1 To icol2
    wkFix.Sheets(1).Cells(j - icol1 + 1, 13) = _
    .Cells(jrow, j)
    Next j
    End With
    End Sub

    In a general module ran fine for me. So the problem must be elsewhere than
    the code shown.

    --
    Regards,
    Tom Ogilvy

    "MaltzMD" <[email protected]> wrote in message
    news:[email protected]...
    > Yes -- jRow is a known quantity, as are iCol1 & iCol2. The printout

    confirms
    > that they are correct.
    >
    > Mike Maltz
    >
    > "Tom Ogilvy" wrote:
    >
    > > is jRow initialized?
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > >
    > > "MaltzMD" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > I have a workbookwith 84 sheets. When I try to select (or activate) a

    > > range I
    > > > get runtime error 1004. In debugging the file, I find I can print the
    > > > individual cells (in a different workbook, wkFix), but cannot select

    the
    > > > range. Here's the relevant code:
    > > >
    > > > With wkState.Sheets("NDX1")
    > > > For j = iCol1 To iCol2
    > > > wkFix.Sheets(1).Cells(j - iCol1 + 1, 13) = .Cells(jRow, j)
    > > > Next j
    > > >
    > > > ' I have no problem in printing
    > > >
    > > > Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select
    > > >
    > > > 'But the above line gives me the runtime error
    > > >
    > > > End With
    > > >
    > > > Can this have anything to do with the number of spreadsheets?
    > > >
    > > > I'm running VBA 6.3, Excel 2003 SP1 with XP Pro
    > > >
    > > > TIA,
    > > > Mike
    > > >

    > >
    > >
    > >




  5. #5
    okaizawa
    Guest

    Re: Runtime Error 1004 on selecting range

    Hi,
    try this, without forgetting the dots,

    .Activate
    .Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select

    or try as a test,

    .Activate
    .Cells(jRow, iCol1).Select
    .Cells(jRow, iCol12).Select
    .Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select

    --
    HTH,

    okaizawa


    MaltzMD wrote:
    > I have a workbookwith 84 sheets. When I try to select (or activate) a range I
    > get runtime error 1004. In debugging the file, I find I can print the
    > individual cells (in a different workbook, wkFix), but cannot select the
    > range. Here's the relevant code:
    >
    > With wkState.Sheets("NDX1")
    > For j = iCol1 To iCol2
    > wkFix.Sheets(1).Cells(j - iCol1 + 1, 13) = .Cells(jRow, j)
    > Next j
    >
    > ' I have no problem in printing
    >
    > Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select
    >
    > 'But the above line gives me the runtime error
    >
    > End With
    >
    > Can this have anything to do with the number of spreadsheets?
    >
    > I'm running VBA 6.3, Excel 2003 SP1 with XP Pro
    >
    > TIA,
    > Mike
    >


  6. #6
    MaltzMD
    Guest

    Re: Runtime Error 1004 on selecting range

    A dumb mistake on my part -- I forgot to put the period before the word
    "Range"!

    Mike Maltz

    "Tom Ogilvy" wrote:

    > is jRow initialized?
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    > "MaltzMD" <[email protected]> wrote in message
    > news:[email protected]...
    > > I have a workbookwith 84 sheets. When I try to select (or activate) a

    > range I
    > > get runtime error 1004. In debugging the file, I find I can print the
    > > individual cells (in a different workbook, wkFix), but cannot select the
    > > range. Here's the relevant code:
    > >
    > > With wkState.Sheets("NDX1")
    > > For j = iCol1 To iCol2
    > > wkFix.Sheets(1).Cells(j - iCol1 + 1, 13) = .Cells(jRow, j)
    > > Next j
    > >
    > > ' I have no problem in printing
    > >
    > > Range(.Cells(jRow, iCol1), .Cells(jRow, iCol2)).Select
    > >
    > > 'But the above line gives me the runtime error
    > >
    > > End With
    > >
    > > Can this have anything to do with the number of spreadsheets?
    > >
    > > I'm running VBA 6.3, Excel 2003 SP1 with XP Pro
    > >
    > > TIA,
    > > Mike
    > >

    >
    >
    >


+ 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