+ Reply to Thread
Results 1 to 19 of 19

For each sh in workbook to insert row

  1. #1
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    For each sh in workbook to insert row

    Hi, is it possible to use the for each sh method to insert row? My current code is this and get object defined errors. Pls help, Thanks in adv.

    Please Login or Register  to view this content.
    Last edited by rename; 12-06-2012 at 04:28 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    That code should work as long as RowNum has a valid value.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    Re: For each sh in workbook to insert row

    Doesn't seem to work sh.range cannot work

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    How does it not work?

    Errors? Incorrect results? Nothing happens?

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: For each sh in workbook to insert row

    What have you declared sh as? What is the value for RowNum?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    Re: For each sh in workbook to insert row

    I got some object define errors. The value in RowNum is UserInput. It still wont work after i changed it into n integer. I declare sh as worksheets.



    Please Login or Register  to view this content.
    I can get this to work. The problem is with the sh.rows. Anyone know how to replace sh.Range("A2") = "Test" into inserting rows for user input? Thanks.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: For each sh in workbook to insert row

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Anyone know how to replace sh.Range("A2") = "Test" into inserting rows for user input?
    Regarding this - change it to
    Please Login or Register  to view this content.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: For each sh in workbook to insert row

    How are you getting input from the user?

  9. #9
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    Re: For each sh in workbook to insert row

    Thanks but thats not what i want. Sorry i think i did not rephrase my question properly. i do not want to have the "test" value in the row number. I want to insert a row in the row number based on the user input eg if user input is 8 then then all those sheets that is not blank in A1 will insert a new row in row 8.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: For each sh in workbook to insert row

    Can you post the code that gets the user input?

    Are you checking that the user actually enter something and that it's valid?

  11. #11
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    Re: For each sh in workbook to insert row

    This is the code

    Please Login or Register  to view this content.
    Error : Select method of range class failed.

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: For each sh in workbook to insert row

    What is RowNum declared as?

  13. #13
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: For each sh in workbook to insert row

    Hi -

    You have a hidden sheets which causing that error.

    Regards,
    Event

  14. #14
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    Re: For each sh in workbook to insert row

    RowNum Is Integer. What do you mean by hidden sheets which cause error? I have no hidden sheets.

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: For each sh in workbook to insert row

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: For each sh in workbook to insert row

    You don't need to select the row and try this
    Please Login or Register  to view this content.
    aelgadi

    > Click Star if I helped. Thanks

  17. #17
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    Re: For each sh in workbook to insert row

    wow thanks. I got it!!
    Last edited by rename; 12-06-2012 at 02:51 AM.

  18. #18
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: For each sh in workbook to insert row

    Try this code - It worked at my end -
    Please Login or Register  to view this content.
    Put it in a standard module.

  19. #19
    Registered User
    Join Date
    11-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003, 2010
    Posts
    73

    Re: For each sh in workbook to insert row

    Thanks you guys very much. Both of the coding works perfect.

+ 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