+ Reply to Thread
Results 1 to 4 of 4

Resuming code in VBA for Excel 2010

  1. #1
    Registered User
    Join Date
    08-10-2013
    Location
    Venezuela
    MS-Off Ver
    Excel 2010
    Posts
    18

    Talking Resuming code in VBA for Excel 2010

    Hi Everyone
    I'm new in VBA for Excel, This code works and make what I want but is too long, how can I resume it? make it shorter, Thanks in advance

    Private Sub TextBox2_Change()
    If Worksheets("userformdata").Range("d2").Value = True Then Worksheets("userformdata").Range("f2").Value = TextBox2.Value
    If Worksheets("userformdata").Range("d3").Value = True Then Worksheets("userformdata").Range("f3").Value = TextBox2.Value
    If Worksheets("userformdata").Range("d4").Value = True Then Worksheets("userformdata").Range("f4").Value = TextBox2.Value
    If Worksheets("userformdata").Range("d5").Value = True Then Worksheets("userformdata").Range("f5").Value = TextBox2.Value
    If Worksheets("userformdata").Range("d6").Value = True Then Worksheets("userformdata").Range("f6").Value = TextBox2.Value
    If Worksheets("userformdata").Range("d7").Value = True Then Worksheets("userformdata").Range("f7").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d8").Value = True Then Worksheets("userformdata").Range("f8").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d9").Value = True Then Worksheets("userformdata").Range("f9").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d10").Value = True Then Worksheets("userformdata").Range("f10").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d11").Value = True Then Worksheets("userformdata").Range("f11").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d12").Value = True Then Worksheets("userformdata").Range("f12").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d13").Value = True Then Worksheets("userformdata").Range("f13").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d14").Value = True Then Worksheets("userformdata").Range("f14").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d15").Value = True Then Worksheets("userformdata").Range("f15").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d16").Value = True Then Worksheets("userformdata").Range("f16").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d17").Value = True Then Worksheets("userformdata").Range("f17").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d18").Value = True Then Worksheets("userformdata").Range("f18").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d19").Value = True Then Worksheets("userformdata").Range("f19").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d20").Value = True Then Worksheets("userformdata").Range("f20").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d21").Value = True Then Worksheets("userformdata").Range("f21").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d22").Value = True Then Worksheets("userformdata").Range("f22").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d23").Value = True Then Worksheets("userformdata").Range("f23").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d24").Value = True Then Worksheets("userformdata").Range("f24").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d25").Value = True Then Worksheets("userformdata").Range("f25").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d26").Value = True Then Worksheets("userformdata").Range("f26").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d27").Value = True Then Worksheets("userformdata").Range("f27").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d28").Value = True Then Worksheets("userformdata").Range("f28").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d29").Value = True Then Worksheets("userformdata").Range("f29").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d30").Value = True Then Worksheets("userformdata").Range("f30").Value = TextBox1.Value
    If Worksheets("userformdata").Range("d31").Value = True Then Worksheets("userformdata").Range("f31").Value = TextBox1.Value
    End Sub


  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Resuming code in VBA for Excel 2010

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-10-2013
    Location
    Venezuela
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Resuming code in VBA for Excel 2010

    Thanks, it works perfect! I'm sorry for rules but I'm new in this forum and want to learn, I'll read rules.
    Thanks again

  4. #4
    Registered User
    Join Date
    08-10-2013
    Location
    Venezuela
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Resuming code in VBA for Excel 2010

    I've other piece of code to make it shorter, can you help me?
    Thanks in advance

    [CODE]
    Private Sub CommandButton11_Click()
    If ToggleButton1.Value = True Then ToggleButton1.Value = False
    If ToggleButton2.Value = True Then ToggleButton2.Value = False
    If ToggleButton3.Value = True Then ToggleButton3.Value = False
    If ToggleButton4.Value = True Then ToggleButton4.Value = False
    If ToggleButton5.Value = True Then ToggleButton5.Value = False
    If ToggleButton6.Value = True Then ToggleButton6.Value = False
    If ToggleButton7.Value = True Then ToggleButton7.Value = False
    If ToggleButton8.Value = True Then ToggleButton8.Value = False
    If ToggleButton9.Value = True Then ToggleButton9.Value = False
    If ToggleButton10.Value = True Then ToggleButton10.Value = False
    If ToggleButton11.Value = True Then ToggleButton11.Value = False
    If ToggleButton12.Value = True Then ToggleButton12.Value = False
    If ToggleButton13.Value = True Then ToggleButton13.Value = False
    If ToggleButton14.Value = True Then ToggleButton14.Value = False
    If ToggleButton15.Value = True Then ToggleButton15.Value = False
    If ToggleButton16.Value = True Then ToggleButton16.Value = False
    If ToggleButton17.Value = True Then ToggleButton17.Value = False
    If ToggleButton18.Value = True Then ToggleButton18.Value = False
    If ToggleButton19.Value = True Then ToggleButton19.Value = False
    If ToggleButton20.Value = True Then ToggleButton20.Value = False
    End Sub
    [CODE]

+ 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. Changing code name of excel 2010 sheet using word 2010 vba
    By samkumar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-17-2013, 08:59 AM
  2. RandBetween code in VB (Excel 2010)
    By teamyoko in forum Excel General
    Replies: 2
    Last Post: 11-26-2012, 01:39 AM
  3. Code for Forms from Word 2010 to Excel 2010
    By birth19 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-29-2011, 05:38 AM
  4. Code for automatically resuming after a message box.
    By HammerTime in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-09-2010, 01:38 AM
  5. Pausing code on Error then resuming once resolved
    By dp_galea in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2007, 05:08 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