+ Reply to Thread
Results 1 to 10 of 10

Why is subscript out of range?

  1. #1
    Registered User
    Join Date
    07-18-2016
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    4

    Question Why is subscript out of range?

    Hi, I just want to copy an entire row (a2) to another sheet (also row (A2), and I have tried using this code:

    Rows(6).EntireRow.Copy
    Sheets(“NMBW”).Range(“A2”).Select
    Sheets("NMBW").Paste

    ... but it warns that "Sheets(“NMBW”).Range(“A2”).Select" is "subscript out of range"..

    I really don't understand, everything seems to be in order?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Why is subscript out of range?

    check the typo of sheet NMBW
    The error means the sheet you are trying to access does not exist on sheet collections.

  3. #3
    Registered User
    Join Date
    07-18-2016
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    4

    Re: Why is subscript out of range?

    But it does exist :/ ... with the exact letters and everything. I am really confused.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Why is subscript out of range?

    Do you have many workbooks opened? The code assumes it is the active workbook.

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Why is subscript out of range?

    Hi,

    You have the wrong kind of quotation marks in that second line. It needs to use straight quotation marks as the subsequent line does:
    Please Login or Register  to view this content.
    rather than:
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Registered User
    Join Date
    07-18-2016
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    4

    Re: Why is subscript out of range?

    Ok, I've changed the quotations, now I get a new error that says on the same line 2:

    "select method of range class failed"

    code is:

    Rows(6).EntireRow.Copy
    Sheets("NMBW").Range("A2").Select
    Sheets("NMBW").Paste

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Why is subscript out of range?

    In order to select a range on a sheet, you must activate that sheet first. However selecting is unnecessary in this case as you can specify the destination for the copied range thus:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-18-2016
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    4

    Re: Why is subscript out of range?

    this worked perfectly thank you!

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Why is subscript out of range?

    You don't even need copy. Just change the 100 in the number of columns you want to copy.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Why is subscript out of range?

    Quote Originally Posted by bakerman2 View Post
    You don't even need copy.
    However your approach assumes that only values are required, of course.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 06-15-2015, 01:56 AM
  2. [SOLVED] Subscript out of range
    By kgakhar in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2013, 04:51 AM
  3. subscript out of range
    By josros60 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2013, 06:33 PM
  4. Subscript out of range
    By JESSIER4025 in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 02-08-2012, 01:19 PM
  5. Subscript out of range error while populating array from range.
    By Aussiexile in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2010, 02:22 AM
  6. Subscript out of range error when trying to select a range
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2010, 07:57 PM
  7. Subscript out of range....
    By Edgar Thoemmes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-12-2005, 11:06 PM

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