[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『listboxについて』(satoru)
一度選択したlistboxを次回起動時に選択行をアクティブにしたいのですが
方法を教授ください。
選択したlistindexを"W1"に書き出し
次回起動時は"W1"を読み込んでアクティブに
よろしくお願いします。
Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 2 ListBox1.ColumnWidths = "200;100" SetRowSource End Sub
Private Sub SetRowSource()
' ActiveSheet.Unprotect
With Sheets(1).Range("AT1") Set RowSourceRng = .Resize(.Item(Rows.Count).End(xlUp).Row, 2) End With RowSourceRng.Sort Key1:=RowSourceRng.Item(1, 2), order1:=xlAscending, _ Header:=xlNo, SortMethod:=xlPinYin ListBox1.RowSource = RowSourceRng.Address(External:=True) End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single) If Len(ActiveCell.Value) = 0 Then ActiveCell.Value = ListBox1.Value Else ActiveCell.Value = ActiveCell.Value & "・" & ListBox1.Value End If Unload Me ActiveCell.Offset(, 1).Select End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("I2:I1000")) Is Nothing Then Cancel = True With 分類 .Show vbModeless .StartUpPosition = 0 End With End If
< 使用 Excel:Excel2016、使用 OS:Windows10 >
Worksheets("買付").Range("W1").Value = Me.ListBox1.ListIndex End Sub 読み込み時のデフォルト行の設定が 以下で実行したのですが listindexプロパティを設定できません プロパティの値が無効です と エラーになります。修正アドバイスお願いします。 ListBox1.ColumnCount = 2 ListBox1.ColumnWidths = "200;100" ListBox1.ListIndex = Worksheets("買付").Range("W1").Value’フォルト行設定 SetRowSource (satoru) 2016/09/24(土) 15:59
いくつか原因があるかもしれませんが、怪しそうなのは、前回の処理でたとえば 20 が保存された。(21行目) 今回ユーザーフォームを表示する際に、ListBox1 のリスト行数が 21行未満だった。
このケースでは、プロパティの値が無効です となりますね。
W1 に 数値ではないもの(xyz という文字列とか)が入っていた場合もエラーになりますが その場合は プロパティの値が無効です ではなく 種類が一致しません というエラーになります。
(β) 2016/09/24(土) 16:13
(satoru) 2016/09/24(土) 16:20
listindexの設定前にSetRowSourceを実行するように順番を入れ替えてみては?
(マナ) 2016/09/24(土) 16:25
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.