iT邦幫忙

0

EXCEL複選選單.欄位帶入資料問題

  • 分享至 

  • xImage

欄位5複選單會選到空白,有沒有辦法可以忽略空白
因為我常常會更新欄位5的選單

Private Sub ListBox1_Change()

    If Reload Then Exit Sub

        For i = 0 To ListBox1.ListCount - 1

            If ListBox1.Selected(i) = True Then t = t & ";" & ListBox1.List(i) '分號「;」為間隔多個選項間的符號,可自行設定
        Next

    ActiveCell = Mid(t, 2)

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

With ListBox1

        If ActiveCell.Column = 6 And ActiveCell.Row > 1 Then '儲存格「欄」為「2」,依照自己的需求修改

            j = ActiveCell.Value

            Reload = True

            For i = 0 To .ListCount - 1

                If InStr(j, .List(i)) Then

                    .Selected(i) = True

                    Else

                    .Selected(i) = False

                End If

            Next

            Reload = False

            .Top = ActiveCell.Top + ActiveCell.Height

            .Left = ActiveCell.Left

            .Width = ActiveCell.Width

            .Visible = True

            Else

            .Visible = False

        End If

    End With

End Sub

https://ithelp.ithome.com.tw/upload/images/20230922/20129304MkgjDNy7qf.png

agout2004 iT邦新手 4 級 ‧ 2023-09-22 11:43:35 檢舉
除了一直修改"ListFillRange"還有別得辦法嗎
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
Hey
iT邦新手 3 級 ‧ 2023-09-27 09:56:07
For i = 0 To ListBox1.ListCount - 1

    ***這裡再加 if, 非空白才繼續, 是想達成這樣嗎?***

            If ListBox1.Selected(i) = True Then t = t & ";" & ListBox1.List(i) '分號「;」為間隔多個選項間的符號,可自行設定
        Next

我要發表回答

立即登入回答