+ Reply to Thread
Results 1 to 11 of 11

userForm loop that returns info back into cells (with some cells not included)

  1. #1
    Registered User
    Join Date
    11-30-2012
    Location
    alberta, canada
    MS-Off Ver
    Excel 2010
    Posts
    39

    userForm loop that returns info back into cells (with some cells not included)

    Good Morning All,

    So I have a userform that when prompted comes up filled with information from cells on a worksheet that the user can then edit and then have those values update. The problem is that the cells: 2, 6, 10, 14, 18, 22, and 26 (Oh look a pattern)(Also those are Column numbers just for Offesting purposes) are not to be tampered with and there for do not have txtBoxes in the userform. I was trying:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    But I end up with Run-time error '-2147024809 (80070057)':
    Could not find the specified object.

    Which is probably becuase there is no Me.Controls("txt" & (2,6,10,etc)) that is can find.
    and it deletes the Cells I don't want it to touch so I changed it to

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then I found out I missnamed a txtBox which was causing me all the grief >.< but now I am wondering if there is a better way to write this since I am still new at vba.

  2. #2
    Registered User
    Join Date
    11-30-2012
    Location
    alberta, canada
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: userForm loop that returns info back into cells (with some cells not included)

    Update,

    So now when I have stuff in the cells that shouldn't be touched if get a similar error from my loop that updates the textbox values before showing the userform and I am sure it is for the same reason so is there a better way to loop while skipping specific i values or is multiple And statements my only sad sorry option?

  3. #3
    Registered User
    Join Date
    11-30-2012
    Location
    alberta, canada
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: userForm loop that returns info back into cells (with some cells not included)

    Update Again,

    So I found that this worked for me.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I will come back later and mark the thread as answer after a few hours to give people some time to add their own ideas and input before saying it was solved (because I know there are those out there that are way better excel then I am).

    Have a great day!

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

    Re: userForm loop that returns info back into cells (with some cells not included)

    What are the textboxes named?
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    11-30-2012
    Location
    alberta, canada
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: userForm loop that returns info back into cells (with some cells not included)

    Right, Forgot to mention that I named the textboxes: txt1, txt3, txt4, txt5, txt7, txt8, txt9, txt11, txt12, etc.
    So that the i would be the the same offset number and same ("txt" & #) as the cell that the textbox is representing.

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

    Re: userForm loop that returns info back into cells (with some cells not included)

    So there's no real pattern to the textbox names?

  7. #7
    Registered User
    Join Date
    11-30-2012
    Location
    alberta, canada
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: userForm loop that returns info back into cells (with some cells not included)

    There is in fact, it is a reverse of the 2, 6, 10, 14 pattern.
    For example, after 2 I skip every 4th number so there is no textboxes named "txt2", then add 4 so no textbox named "txt6" and again add 4 so no textbox "txt10", etc. Each textboxes number ("txt1" 1<--- that number) is the box that should be equal to the offset number that is "i". If that makes any sense.

  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: userForm loop that returns info back into cells (with some cells not included)

    Do you need to use a loop and offset?

  9. #9
    Registered User
    Join Date
    11-30-2012
    Location
    alberta, canada
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: userForm loop that returns info back into cells (with some cells not included)

    That was generally the idea I went with (sorry, had a meeting =.=)

    Basically, the user selects a persons name in cell A1 which then becomes the activecell, they then click a button that opens a userform that needs the textboxes to update based on the staff member selected. This is the code that I used to do that:
    Please Login or Register  to view this content.
    Then the user changes anything that needs to be changed and hits "Done" which runs:

    Please Login or Register  to view this content.
    I am sure there are fancier ways to do it but that was the best that I was able to come up with with my limited vba knowledge.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    There might be other approaches, hard to tell without knowing exactly what's going on.

    Could you attach a sample workbook?

  11. #11
    Registered User
    Join Date
    11-30-2012
    Location
    alberta, canada
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: userForm loop that returns info back into cells (with some cells not included)

    Sorry about the wait, was sick yestarday.

    Here is an example of the code in action.

    BookOffEx.xlsm

    Any questions just let me know!

    (Oh ya, I don't have auto Calculate on so keep that in mind)
    Last edited by Sleepyshy; 12-13-2012 at 12:15 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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