2016-07-07 16 views
2

ユーザーフォーム(SecurityRadioとSafteyRadio)に2つのオプションボタンがあります。セキュリティラジオをクリックすると、シート名 "セキュリティ"にフィルタを適用し、その新しい範囲を変数名に割り当てたいとします。 SwitchesRadioでは、同じ手順を別のシートで行う必要があります。VBAタイプの不一致(13)

しかし、SwitchesRadioを選択してGoボタンをクリックすると、別のユーザーフォームのリストボックスに新しい範囲を割り当てるときにエラーが発生します。エラーは、ランタイムエラー13、 "Type mismatch" .ListBox2 ..最後(コメント参照)の近くです。どのように私はこれを修正することができますどのような考え?

Private Sub GoButton_Click() 
Dim Security As Worksheet, Switches As Worksheet, CurrentSheet As Worksheet 
Dim LastAddressCurrent1 As Range, LastRowCurrent1 As Long, LastColCurrent1 As Long 
Dim LastAddressCurrent2 As Range, LastRowCurrent2 As Long, LastColCurrent2 As Long 
Dim RA_Range As Range, Comp_Range As Range 

If SwitchesRadio Then 
    Set CurrentSheet = Sheets("Switches") 
ElseIf SecurityRadio Then 
    Set CurrentSheet = Sheets("Security") 
Else 
    MsgBox "Please select a product type to continue" 
End If 

'retrieve the last cell row number and column 
With CurrentSheet 
    Set LastAddressCurrent1 = .Cells(.Rows.Count, "A").End(xlUp) 
    LastRowCurrent1 = LastAddressCurrent1.Row 
    LastColCurrent1 = Cells(1, Columns.Count).End(xlToLeft).Column 
End With 

CurrentSheet.Range(Cells(2, 1), Cells(LastRowCurrent1, LastColCurrent1)).AutoFilter Field:=2, Criteria1:="RA" 
    With CurrentSheet 
    Set LastAddressCurrent2 = .Cells(.Rows.Count, "A").End(xlUp) 
    LastRowCurrent2 = LastAddressCurrent2.Row 
    LastColCurrent2 = Cells(1, Columns.Count).End(xlToLeft).Column 
    End With 
Set RA_Range = CurrentSheet.Range(Cells(2, 1), Cells(LastRowCurrent2, LastColCurrent2)) 
CurrentSheet.ShowAllData 
CurrentSheet.Range(Cells(2, 1), Cells(LastRowCurrent1, LastColCurrent1)).AutoFilter Field:=2, Criteria1:="Comp" 
    With CurrentSheet 
    Set LastAddressCurrent2 = Cells(.Rows.Count, "A").End(xlUp) 
    LastRowCurrent2 = LastAddressCurrent2.Row 
    LastColCurrent2 = Cells(1, Columns.Count).End(xlToLeft).Column 
    End With 
Set Comp_Range = CurrentSheet.Range(Cells(2, 1), Cells(LastRowCurrent2, LastColCurrent2)) 
CurrentSheet.ShowAllData 

'Assign names to appropriate list boxes 
With MainSelectionForm 
.ListBox2.RowSource = RA_Range ****** errors here 
.ListBox1.RowSource = Comp_Range 

End With 
End Sub 

答えて

0

おそらくRangeがオブジェクトであるとしてRowSourceRA_Range.Addressを割り当てます。

はここ
https://msdn.microsoft.com/en-us/library/office/gg251646.aspx

が範囲のプロパティに関する情報(半押し)
https://msdn.microsoft.com/en-us/library/office/ff197454.aspx

+1

勤務値集合ソースの使用量の非常に単純な例です!本当にありがとう。 – Liz

+0

私はエラーを乗り越えることができましたが、リストボックスを見ると領域を選択できますが、単語は表示されません。単語を引っ張ることとアドレッシングが競合しますか? – Liz

+0

申し訳ありませんが、私はRowSourceの使い方を誤解しています。 .AddressはRangeのAddressを含む文字列を返します。もう少し調べてみると、http://stackoverflow.com/a/30933151/4541045があなたと同じ問題を抱えているように見え、啓発されているかもしれません。 RowSourceは完全なシート名と範囲を期待しているようですが、文字列ハッカーで修正できないものは何もありません。 – ti7

関連する問題