Array pulls in incorrect data from worksheet

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,732
Office Version
  1. 2007
Platform
  1. Windows
I have the following code in a module.
Rich (BB code):
 Option Base 1

Function ControlNames() As Variant
ControlNames = Array("txtCustomer", "txtRegistrationNumber", "txtBlankUsed", "txtVehicle", _
                    "txtButtons", "txtKeySupplied", "txtTransponderChip", "txtJobAction", _
                    "txtProgrammerCloner", "txtKeyCode", "txtBiting", "txtChassisNumber", _
                    "txtJobDate", "txtVehicleYear", "txtPaid", "txtInvoiceNumber", "TextBox1", _
                    "TextBox2", "TextBox3", "TextBox4", "TextBox5", "TextBox6", "TextBox7", "TextBox9", "txtPinCode")
End Function

Function IsComplete(ByVal Form As Object) As Boolean
    Dim i As Integer
    For i = 1 To UBound(ControlNames)
        IsComplete = CBool(Len(Form.Controls(ControlNames(i)).Text) > 0)
        If Not IsComplete Then
            MsgBox "PLEASE COMPLETE ALL FIELDS", 17, "Entry Required"
            Form.Controls(ControlNames(i)).BackColor = vbMagenta
            Form.Controls(ControlNames(i)).SetFocus
            Exit Function
        End If
    Next i
End Function

All the above entries from my worksheet to userform are correct APART from TextBox9
In TextBox9 the value has been taken from worksheet column X which is incorrect as it should be taking the value from column AB

My issue is looking at all the code for hours i just cant see or find what tells the userform fields where to get data from to populate them.
Ive looked for at least 2 hours this morning.

Does the code above advise you of anything thanks.
Something is happening as TextBox9 is being populate but trying to locate what is telling it to look at column what column
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
"TextBox9" is the 24th entry in ControlNames ... the 24th letter of the alphabet is X
 
Upvote 0
Ok I now see that but what or how do I achieve the Textbox9 pulling from AB

Thanks.
 
Upvote 0
One way would be to check the value of 'i' and if it is 24 then change it to 28 ... then before the 'Next i' line of code,Check if 'i' is 28 and if it is set the value of 'i' back to 24.
 
Upvote 0
That is not the best way to do it, but in this case it should work.
 
Upvote 0
I will check tomorrow.
I don’t think it will be 24 as today I added an the extra Textbox.
So before I did that for what reason would 24 be there
 
Upvote 0
You could add a separate array for the column numbers.

Or create a dictionary where the keys are the control names and the values are the columns.
 
Upvote 0
Thanks but unable to locate the code so i will go to plan B

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,617
Latest member
Narendra Babu D

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