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