Excel User Form - auto populate field

grapevine

Board Regular
Joined
May 23, 2007
Messages
208
I have set up the code to filter the contents of column A. This feeds into a combo box which users can select.
My problem occurs when I want to autopopulate a subsequent field in the user form with a value from the same line. the code that I did have working looks at the contents of the whole column ignoring the filter that is in place.

My code to filter is when the form opens
<code>
Sub InputOffersForm()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Team Vals - Take ons")
With ws
.AutoFilterMode = False 'tblTakeons is a dynamic named range to select the growing list of data

End With

Sheet1.Range("G11:G65000").Copy 'this is to check the correct data is in column a
Sheet1.Range("A11").PasteSpecial
Application.CutCopyMode = False

With ws
With .Range("tblTakeons") 'tblTakeons is a dynamic named range to select the growing list of data
.Autofilter Field:=32, Criteria1:="Live" ' column 32 is the column to filter by
End With
End With
frmOffers.Show
End Sub
</code>

My code to populate the combo box is as follows:
<code>
rivate Sub UserForm_Initialize()

Dim copyfrom As Range, aCell As Range
With Sheet1.Range("tblTakeons")

Set copyfrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible)

For Each aCell In copyfrom
If aCell.Column = 1 Then _
Me.cboProperty.AddItem aCell.Value
Next
End With

Me.cboNegotiator.Value = "--Select--"
Me.cboOffice.Value = "--Select--"
Me.cboposition.Value = "--Select--"
Me.cboOffice1.Value = "--Select--"
Me.cboNeg1.Value = "--Select--"

End Sub
</code>

The code below is I am getting the error, (I have only included the above for information)

the error message is Run-time error '-2147352571 (80020005)':
Could not set the Value property. Type mismatch

I would be grateful is someone could point out my coding error. I have played around with various combinations, but as yet can get the code to run by using offset so I know I am not using the correct syntax.

<code>
Private Sub cboProperty_change()
If cboProperty.ListIndex <> -1 Then

'cboLister1.Value = Worksheets("Team Vals - Take ons").Range("tblTakeons").cells(cboProperty.ListIndex + 2, 4).Value - the above is the original code which worked on an unfiltered list

cboLister1.Value = Worksheets("Team Vals - Take ons").Range("tblTakeons").cells.Offset(0, 4).SpecialCells(xlCellTypeVisible)
'the above line is my attempt at trying to get the data from the 4th column along from the source of the information.

txtLister1PC = "100"
txtCurrentPrice.Value = Worksheets("Team Vals - Take ons").Range("tblTakeons").cells(cboProperty.ListIndex + 1, 12).Value
cboPriceType.Value = Worksheets("Team Vals - Take ons").Range("tblTakeons").cells(cboProperty.ListIndex + 1, 13).Value
txtPriceFrom.Value = Worksheets("Team Vals - Take ons").Range("tblTakeons").cells(cboProperty.ListIndex + 1, 14).Value

End If
End Sub
</code>

Many, many thanks in advance
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,216,163
Messages
6,129,223
Members
449,495
Latest member
janzablox

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