要用VBA 應用 , 自己寫了一段程式,是為了在list box 只列出單一值(A,B,C,D,E,F,G)給人員方便點選。
但總覺得程式很長,可否幫忙簡化呢?
For I = 1 To 20
A = 0
Text_Flag = Area.Cells(I, 1)
For J = 0 To Dept_Observing.ListCount - 1
If Dept_Observing.List(J) = Text_Flag Then
A = 1
Exit For
End If
Next J
If A = 0 And Text_Flag <> "" Then
Dept_Observing.AddItem Text_Flag
End If
Next I作者: linshin1999 時間: 2011-1-16 20:14
Dim Text_Flag as Range
Dim sd() as integer, sd_val as integer
For Each Text_Flag In Selection
Sd_val = Asc(Text_Flag.Value)
If sd(s_val) = 0 Then
sd(s_val) = 1
Dept_Observing.AddItem Text_Flag.Value
End If
Next作者: et5323 時間: 2011-1-16 21:46
Sub test()
Dim arr, oDic As Object, i
Set oDic = CreateObject("scripting.dictionary")
With Sheet1
arr = .Range("a1:a" & .[a65536].End(xlUp).Row)
End With
For i = 1 To UBound(arr)
oDic(arr(i, 1)) = ""
Next
Dept_Observing.List = oDic.keys
Set oDic = Nothing
End Sub