+ Reply to Thread
Results 1 to 4 of 4

Is there a way to rewrite this code for a UserForm in loop form?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Is there a way to rewrite this code for a UserForm in loop form?

    I don't know how to rewrite this in loop form because the numbers are attached to the word i.e. "textbox1" instead of textbox(1). I know how to loop through the cells, but not through the different textboxes.

    With Worksheets("Sheet1")
    
        .Cells(20, 1) = TextBox1.Value
        .Cells(21, 1) = TextBox2.Value
        .Cells(22, 1) = TextBox3.Value
        .Cells(23, 1) = TextBox4.Value
        .Cells(24, 1) = TextBox5.Value
        .Cells(25, 1) = TextBox6.Value
        .Cells(26, 1) = TextBox7.Value
        .Cells(27, 1) = TextBox8.Value
        
        .Cells(20, 2) = ListBox1.Value
        .Cells(21, 2) = ListBox2.Value
        .Cells(22, 2) = ListBox3.Value
        .Cells(23, 2) = ListBox4.Value
        .Cells(24, 2) = ListBox5.Value
        .Cells(25, 2) = ListBox6.Value
        .Cells(26, 2) = ListBox7.Value
        .Cells(27, 2) = ListBox8.Value
    
    End With
    Last edited by bananajelly; 08-05-2014 at 05:24 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Is there a way to rewrite this code for a UserForm in loop form?

    Quote Originally Posted by bananajelly View Post
    I don't know how to rewrite this in loop form because the numbers are attached to the word i.e. "textbox1" instead of textbox(1). I know how to loop through the cells, but not through the different textboxes.

    With Worksheets("Sheet1")
    
    for x = 1 to 2
    
    for i = 1 to 8
        .Cells(19 + i, x ) = TextBox & i.Value
    next i
    
    next x
    
    End With
    I don't know if that would work or not....untested
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

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

    Re: Is there a way to rewrite this code for a UserForm in loop form?

    Try this.
    With Worksheets("Sheet1")
        For I = 20 To 27
            
        .Cells(I, 1) = Me.Controls("TextBox" & I - 19).Value
        .Cells(I, 2) = Me.Controls("ListBox" & I - 19).Value
        Next I
    End With
    Last edited by Norie; 08-07-2014 at 01:23 PM.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Is there a way to rewrite this code for a UserForm in loop form?

    Thanks Norie!

+ 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. [SOLVED] Rewrite existing code to include date in filename
    By MissaLissa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2013, 01:03 PM
  2. [SOLVED] Looking for help with speeding up or rewrite on vba code.
    By ukchris74 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-16-2013, 01:54 PM
  3. [SOLVED] Outlook 2010: Rewrite VBA Code
    By Cansa in forum Outlook Formatting & Functions
    Replies: 3
    Last Post: 10-12-2012, 12:25 PM
  4. Need to rewrite protect code so that it will work with a hidden sheet.
    By mrgillus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2009, 08:17 PM
  5. how would I rewrite this userform-to-worksheet procedure as a loop?
    By durandal05 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2008, 05:00 PM

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