同じなのにNG、違うのにOK?
ユーザーフォームにコンボボックスとボタンを配置して、↓のコードを書いたとします。
Private Sub UserForm_Initialize() Me.ComboBox1.List = Array(1, "2") Me.ComboBox1.Style = fmStyleDropDownList End Sub Private Sub CommandButton1_Click() MsgBox Me.ComboBox1.List(0) & vbCrLf _ & TypeName(Me.ComboBox1.List(0)) & vbCrLf _ & Me.ComboBox1.List(1) & vbCrLf _ & TypeName(Me.ComboBox1.List(1)) On Error Resume Next Debug.Print "◆数値の 1 を代入◆・・・《イ》" Err.Clear Me.ComboBox1.Value = 1 Debug.Print Err.Number, Err.Description Debug.Print "◆文字列の 1 を代入◆・・・《ロ》" Err.Clear Me.ComboBox1.Value = "1" Debug.Print Err.Number, Err.Description Debug.Print "◆数値の 2 を代入◆・・・《ハ》" Err.Clear Me.ComboBox1.Value = 2 Debug.Print Err.Number, Err.Description Debug.Print "◆文字列の 2 を代入◆・・・《ニ》" Err.Clear Me.ComboBox1.Value = "2" Debug.Print Err.Number, Err.Description On Error GoTo 0 End Sub
《イ》《ニ》はOKで、
《ロ》《ハ》はNGになりそうな気がします。
でも、試すと《ハ》《ニ》だけがOKです。
納得いきません。むぅ。
※.Excel World の 2008年1月29日 00:28 の日記をコピーしています。
http://excel.sns.fc2.com/excel/