Userforms - Inconsistent Transfer from Cell Reference to TextBox

Don Carlos

New Member
Joined
Feb 1, 2016
Messages
5
(Excel 2010 - 32 Bit on Windows 7 Enterprise)

Hello,

I ask for your assistance with transferring data between an Excel Sheet and a userform. The userform is intended to both capture (write to an Excel sheet) and retrieve (from the same Excel sheet).

My problem is that, when I debug the code, cell reference contents will not consistently be captured into the textboxes. Usually, either the 'PrimaryRisk' is successful in reporting the information from the sheet and the 'SecondaryRisk' is not, or vice versa (in coming up Null).

Below is a sample of the code, which is purposely overly redundant to see if a method is consistently reliable. Typically, it will work or it won't for any of the methods in that set.


Code:
'PrimaryRisk
        With UserForm3.PrimaryRisk
            .Text = Sheet4.Cells(nSelectedRecord + 1, 3)
            .Value = Sheet4.Cells(nSelectedRecord + 1, 3)
        End With
        If UserForm3.PrimaryRisk.Text = "" Then
            UserForm3.PrimaryRisk.Value = Sheet4.Cells(nSelectedRecord + 1, 3)
        End If
        If UserForm3.PrimaryRisk.Text = "" Then
            tTempText = Sheet4.Cells.Cells(nSelectedRecord + 1, 3).Value
            UserForm3.PrimaryRisk.Text = tTempText
        End If
        If UserForm3.PrimaryRisk.Text = "" Then
            UserForm3.PrimaryRisk.Value = Sheet4.Cells(nSelectedRecord + 1, 3).Value
        End If
        UserForm3.PrimaryRiskText.Value = WorksheetFunction.VLookup(UserForm3.PrimaryRisk.Value, Range("RISKTABLE"), 2, False)
        'SecondaryRisk (Optional)
        If Sheet4.Cells(nSelectedRecord + 1, 4) = "" Or Sheet4.Cells(nSelectedRecord + 1, 4) = 0 Then
            UserForm3.SecondaryRisk.Text = ""
            UserForm3.SecondaryRiskText.Value = ""
        Else
            With UserForm3.SecondaryRisk
                .Text = Sheet4.Cells(nSelectedRecord + 1, 4).Value
                .Value = Sheet4.Cells(nSelectedRecord + 1, 4).Value
            End With
            UserForm3.SecondaryRisk.Value = Sheet4.Cells(nSelectedRecord + 1, 4)
            If UserForm3.SecondaryRisk.Text = "" Then
                tTempText = Sheet4.Cells.Cells(nSelectedRecord + 1, 3).Value
                UserForm3.SecondaryRisk.Text = tTempText
            End If
            If UserForm3.SecondaryRisk.Text = "" Then
                UserForm3.SecondaryRisk.Value = Sheet4.Cells(nSelectedRecord + 1, 3).Value
            End If
            UserForm3.SecondaryRiskText.Value = WorksheetFunction.VLookup(UserForm3.SecondaryRisk.Value, Range("RISKTABLE"), 2, False)
        End If
Notes:
1. I have tried to interchange between .value and .text without a change in results.
2. nSelectRecord is either 1 if not determined by the user or the record number selected by the user.
3. tTempText is usually successful in capturing the Excel sheet information, but is usually not successful in being written into the textbox.

Thank you in advance for your assistance.
 

Don Carlos

New Member
Joined
Feb 1, 2016
Messages
5
The code is connected to the "edit" command button on the userform.

Interestingly, the userform is reliable for collecting information and pasting onto a sheet using the reverse order of the code shared in this post (userform.textbox -> sheet.cell()).
 

Don Carlos

New Member
Joined
Feb 1, 2016
Messages
5
I agree. The additional interesting thing is that if it works, they all work, say for primary risk. The redundant code does not overwrite a successful collection. But if it does not work on the first line, it will not correct itself in the redundant code.

My own thought is that the cause may be copying the textbox rather than recreating the textbox from the toolbox. But this is just a thought.
 

Don Carlos

New Member
Joined
Feb 1, 2016
Messages
5
I did find a solution to my problem. I was able to reliably capture information from a spreadsheet tab into the userform using ".ControlSource" property and referencing unique cell reference for each textbox and listbox. An example is:

Code:
UserForm3.CostTimeFrame.ControlSource = "Reference!$Q$3"
.
 

Forum statistics

Threads
1,081,852
Messages
5,361,690
Members
400,648
Latest member
mamamia93

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top