2
我使用下面的代碼將項目從ListBox
添加到Sheet1
。一切正常,但我點擊「添加」後,工作表不刷新。只有當我關閉表單時纔會看到更改(添加的行)。從列表框中寫入後刷新工作表
Private Sub btnAdd_Click()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim wbc As Workbook
Dim wsc As Worksheet
Set wbc = ActiveWorkbook
Set wsc = wbc.Worksheets("Sheet1")
Dim addme As Range
Dim x, y As Integer
Set addme = Application.Selection
For x = 0 To Me.lbsourceList.ListCount - 1
If Me.lbsourceList.Selected(x) Then
addme.Offset(1).EntireRow.Insert
wsc.Range(Cells(addme.Row, "C"), Cells(addme.Row, "C")).Offset(1).Value = Me.lbsourceList.List(x, 0)
wsc.Range(Cells(addme.Row, "I"), Cells(addme.Row, "I")).Offset(1).Value = Me.lbsourceList.List(x, 1)
Set addme = addme.Offset(1, 0)
End If
Next x
For y = 0 To Me.lbsourceList.ListCount - 1
If Me.lbsourceList.Selected(y) Then Me.lbsourceList.Selected(y) = False
Next y
End Sub
代碼運行後工作表是否可以更新/刷新?
你可以試試'Workbooks(「your_wb_name」)。RefreshAll' – Wujaszkun