+ Reply to Thread
Results 1 to 5 of 5

Excel VBA Code to make my Toggle Buttons output "Yes" or "No" to their cells

Hybrid View

mebanet Excel VBA Code to make my... 08-06-2013, 04:06 AM
mebanet Re: Excel VBA Code to make my... 08-06-2013, 04:07 AM
Norie Re: Excel VBA Code to make my... 08-06-2013, 04:11 AM
mebanet Re: Excel VBA Code to make my... 08-06-2013, 05:59 AM
Norie If it's not tgo followed by... 08-06-2013, 06:14 AM
  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    11

    Excel VBA Code to make my Toggle Buttons output "Yes" or "No" to their cells

    I need help getting the following code to work:

    'Saves data entered into the UserForm into the current row
    Private Sub cmdSave_Click()
    Dim ctl As Control
    cmdSave.Enabled = True
    cmdSearch.Enabled = True
    cmdFirst.Enabled = True
    cmdPrevious.Enabled = True
    cmdClose.Enabled = True
    cmdNext.Enabled = True
    cmdLast.Enabled = True
    Cells(r, 1).Select
    For Each ctl In Me.Controls
        If ctl.Name Like "tgo?" Then
            If ctl.Value = True Then
                Cells.Value = "Yes"
            Else
                Cells.Value = "No"
            End If
        End If
    Next ctl
          
        Cells(r, 1).Value = Me.txtCX1.Value
        Cells(r, 2).Value = Me.txtCX2.Value
        Cells(r, 3).Value = Me.txtCX3.Value
        Cells(r, 4).Value = Me.txtCX4.Value
        Cells(r, 5).Value = Me.txtCX5.Value
        Cells(r, 6).Value = Me.cboCX6.Value
        Cells(r, 7).Value = Me.txtCX7.Value
        Cells(r, 8).Value = Me.tgoCX8.Value
        Cells(r, 9).Value = Me.txtCX9.Value
        Cells(r, 10).Value = Me.tgoCX10.Value
        Cells(r, 11).Value = Me.tgoCX11.Value
        Cells(r, 12).Value = Me.tgoCX12.Value
        Cells(r, 13).Value = Me.txtCX13.Value
        Cells(r, 14).Value = Me.txtCX14.Value
        Cells(r, 15).Value = Me.txtCX15.Value
        Cells(r, 16).Value = Me.txtCX16.Value
        Cells(r, 17).Value = Me.txtCX17.Value
        Cells(r, 18).Value = Me.txtCX18.Value
        Cells(r, 19).Value = Me.txtCX19.Value
        Cells(r, 20).Value = Me.txtCX20.Value
        Cells(r, 21).Value = Me.txtCX21.Value
        Cells(r, 22).Value = Me.txtCX22.Value
        Cells(r, 23).Value = Me.txtCX23.Value
        Cells(r, 24).Value = Me.txtCX24.Value
        Cells(r, 25).Value = Me.txtCX25.Value
        Cells(r, 26).Value = Me.tgoCX26.Value
        Cells(r, 27).Value = Me.tgoCX27.Value
        Cells(r, 28).Value = Me.tgoCX28.Value
        Cells(r, 29).Value = Me.tgoCX29.Value
    End Sub
    Right now I can get what I want by doing this:

        If Me.tgoCX8.Value = True Then
        Cells(r, 8).Value = "Yes"
        Else
        Me.tgoCX8.Value = False
        Cells(r, 8).Value = "No"
        End If
    But there are over 100 toggle buttons on my UserForm and I don't want to have to do that for every one. All my Toggle Buttons start with "tgo".

    Thanks in advance

  2. #2
    Registered User
    Join Date
    07-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Excel VBA Code to make my Toggle Buttons output "Yes" or "No" to their cells

    oh and:

    r = ActiveCell.Row

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

    Re: Excel VBA Code to make my Toggle Buttons output "Yes" or "No" to their cells

    If the number after 'tgo' is the column number perhaps this.
    For Each ctl In Me.Controls
        If ctl.Name Like "tgo?" Then      
           Cells(r, Mid(ctl.Name, 4)) = Iif(ctl.Value, "Yes", "No")
        End If
    Next ctl
    Last edited by Norie; 08-06-2013 at 04:13 AM.
    If posting code please use code tags, see here.

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

    Re: Excel VBA Code to make my Toggle Buttons output "Yes" or "No" to their cells

    that didn't work, the number after tgo is the column number though... 'tgoCX10" will write to the current row column 10

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    If it's not tgo followed by the column number what is it?

+ 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] Excel 2010 -- "Visual Basic" "Macros" and "Record Macro" all disabled.
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2017, 06:11 AM
  2. Request - "write vba code on buttons to make attached user form complete"
    By virgome in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2013, 02:12 PM
  3. If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ...
    By Maria J-son in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2006, 08:25 AM
  4. Replies: 6
    Last Post: 01-08-2006, 06:20 PM
  5. Replies: 3
    Last Post: 10-25-2005, 07:05 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