我有一個VBA代碼,其被連接到一個用戶窗體不重複VBA代碼
的代碼搜索列標題和通過從用戶窗體
我的問題採取的值與這些標題的列填充是:我怎樣才能避免重複的代碼?
Dim intBB As Integer
Dim rngBB As Range
intBB = 1
Do While ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB) <> ""
If ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB).Value = "Block" Then
With ActiveWorkbook.Worksheets("Sheet1")
Set rngBB = .Range(.Cells(1, intBB), .Cells(1, intBB))
End With
Exit Do
End If
intBB = intBB + 1
Loop
ActiveWorkbook.Worksheets("Sheet1").Range(Cells(2, intBB), Cells(LastRow, intBB)).Value = BlockBox.Value
intBB = 1
Do While ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB) <> ""
If ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB).Value = "HPL" Then
With ActiveWorkbook.Worksheets("Sheet1")
Set rngBB = .Range(.Cells(1, intBB), .Cells(1, intBB))
End With
Exit Do
End If
intBB = intBB + 1
Loop
ActiveWorkbook.Worksheets("Sheet1").Range(Cells(2, intBB), Cells(LastRow, intBB)).Value = HPLBox.Value
適合在陣列中提到的控制,並從那裏閱讀它們! :)我太懶了:) – Vityata
@Vityata - 謝謝,我知道這種感覺!如果控件都是搜索項+'Box',那麼可以省去第二個數組,但不想假設。 – SJR