Populating textboxes with values from two columns of textboxes

ryeire

New Member
Joined
Jan 31, 2022
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am creating a database that is used for doing checks and logging required info.

I have a userform where you insert two seperate readings for each station along with pass/fail option buttons.
I'm looking to populate one textbox in a seperate userform with the values from one column of textboxes in the current userform, and I wish to do the same with another column of textboxes in the same userform. I have code that will allow me to complete this action but with only one column of textboxes. See pictures of userforms below.

I also attached the code that I have below. I have named the textboxes in each column the same with only the number changing (e.g. textbox1, textbox2) and I have been trying to use the control methods to accomplish what I want but I have had no luck so far.

VBA Code:
Dim t As MSForms.Control, v
v = ""
For Each t In Me.Controls
    If TypeOf t Is MSForms.TextBox Then
        v = v & IIf(v <> "", ", ", "") & Trim(t.Value)
    End If
Next t
frmQuarterlyForm.txtMatGND.Value = v

I hope someone can help me with my issue. Thanks in advance
 

Attachments

  • ESD Quarterly Check.png
    ESD Quarterly Check.png
    40.6 KB · Views: 6
  • ESD Quarterly Check (1).png
    ESD Quarterly Check (1).png
    3 KB · Views: 6

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,904
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hi,
untested but see if following will do what you want

Rich (BB code):
    Dim i               As Long, a As Long
    Dim Results(1 To 2) As String
 
    For i = 1 To 24
        a = IIf(i < 13, 1, 2)
        With Me.Controls("TextBox" & i)
            If Len(.Value) > 0 Then
                Results(a) = Results(a) & .Value & IIf(i = 12 Or i = 24, "", ",")
            End If
        End With
    Next i
 
    With frmQuarterlyForm
        .txtMatGND.Value = Results(1)
        .txtContGND.Value = Results(2)
    End With

Change control name shown in BOLD as required

Dave
 
Solution

ryeire

New Member
Joined
Jan 31, 2022
Messages
31
Office Version
  1. 365
Platform
  1. Windows
@dmt32 sorry for the late reply. I just tested the code and it works perfectly. Thank you very much for your time and help
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,904
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
I just tested the code and it works perfectly. Thank you very much for your time and help

Hi,
not sure solution is "perfect" but glad if seems to do what you want & appreciate your feedback

Dave
 

Forum statistics

Threads
1,186,124
Messages
5,955,977
Members
438,230
Latest member
Meemaw2212

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top