+ Reply to Thread
Results 1 to 6 of 6

Impossible to add worksheet!

  1. #1
    Registered User
    Join Date
    06-23-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    25

    Impossible to add worksheet!

    I am trying to write a VBA function to write an array to a worksheet to help me debug problems.
    I have tried all the variants shown after 'Add worksheet and none of them will add a new worksheet to the workbook. I have not even gotten to the part about writing out the array. So simple and so frustrating that there must be a simple answer!
    Thank you for your help.

    Sub Array2Range(arrx As Variant)
    Dim NumRow As Long, NumCol As Long
    Dim WriteRange As Range

    NumRow = NumElements(arrx, 1)
    NumCol = NumElements(arrx, 2)

    'Add worksheet
    'Set sh = ThisWorkbook.Worksheets.Add
    'sh.Name = "MySheet"

    'Worksheets.Add(After:=Sheets(Sheets.Count)).Name = "MySheet"

    'Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "MySheet"

    'Worksheets.Add , Worksheets(Worksheets.Count)
    'ActiveSheet.Name = "Array"

    'Write array to new worksheet
    Set WriteRange = Range(ActiveSheet.Cells(1, 1), ActiveSheet.Cells(NumRow, NumCol))
    WriteRange.Value = arrx

    End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Impossible to add worksheet!

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-23-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Impossible to add worksheet!

    I am trying to write a VBA function to write an array to a worksheet to help me debug problems.
    I have tried all the variants shown after 'Add worksheet and none of them will add a new worksheet to the workbook. I have not even gotten to the part about writing out the array. So simple and so frustrating that there must be a simple answer!
    Thank you for your help.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Impossible to add worksheet!

    All of those versions should work (if they weren't commented out), unless your workbook is protected. What exactly is happening? Nothing, an error, or what? (If it's an error, what error?)
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    06-23-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    25

    Unhappy Re: Impossible to add worksheet!

    Romperstomper (love the screen name)
    The workbook and sheet are not protected.
    I observe no error indication. Stepping through the function seems normal - the command executes and goes on to the next.
    There is nothing to see in Locals.
    Is there another diagnostic view that would show why this command fails to perform?
    I recorded a macro to add a sheet and name it. Running this from inside the VBA routine, I see that the Properties window changes to Sheet2 but no sheet is added. The subsequent name command terminates, presumably as there is no Sheet2 to rename.

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Impossible to add worksheet!

    If you're using this version:
    Please Login or Register  to view this content.
    then you ought to be able to view sh in the Locals window (or the Watch window if you set a watch on it). Does this fail in all workbooks or just one?

+ 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