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: 7

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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
 
Upvote 0
Solution
@dmt32 sorry for the late reply. I just tested the code and it works perfectly. Thank you very much for your time and help
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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
Back
Top