0
爲學校做一個項目,我可以將數據讀入我的表格,但我似乎無法從我的表格更新,然後移動到一個新的記錄。有人可以請幫助。如何從VBA表單更新電子表格?
Private Sub Next_Command_Click()
Do
nCurrentRow = nCurrentRow + 1
TraverseData (nCurrentRow)
Loop Until NC_C_L.Cells(nCurrentRow, 1).Value = "" Or NC_C_L.Cells(nCurrentRow, 1).Value = Me.***_Text.Value
End Sub
Private Sub Previous_Command_Click()
Do
nCurrentRow = nCurrentRow - 1
TraverseData (nCurrentRow)
Loop Until nCurrentRow = 1 Or NC_C_L.Cells(nCurrentRow, 1).Value = Me.***_Text.Value
End Sub
Private Sub TraverseData(nRow As Long)
Me.***_Text.Value = NC_C_L.Cells(nRow, 1)
Me.***_Box = NC_C_L.Cells(nRow, 2)
Me.***_Combo.Value = NC_C_L.Cells(nRow, 3)
Me.***_Combo.Value = NC_C_L.Cells(nRow, 4)
Me.***_Combo.Value = NC_C_L.Cells(nRow, 5)
Me.***_Combo.Value = NC_C_L.Cells(nRow, 6)
Me.***_Combo.Value = NC_C_L.Cells(nRow, 7)
Me.***_Text.Value = NC_C_L.Cells(nRow, 8)
Me.***_Text.Value = NC_C_L.Cells(nRow, 9)
Me.Comments1_Text.Value = NC_C_L.Cells(nRow, 10)
Me.Comments2_Text.Value = NC_C_L.Cells(nRow, 11)
Me.Comments3_Text.Value = NC_C_L.Cells(nRow, 12)
Me.PhoneNumber_Text.Value = NC_C_L.Cells(nRow, 13)
Me.Address1_Text.Value = NC_C_L.Cells(nRow, 14)
Me.Address2_Text.Value = NC_C_L.Cells(nRow, 15)
Me.City_Text.Value = NC_C_L.Cells(nRow, 16)
Me.State_Combo.Value = NC_C_L.Cells(nRow, 17)
Me.Zip_Text.Value = NC_C_L.Cells(nRow, 18)
Me.EMail_Text.Value = NC_C_L.Cells(nRow, 19)
Me.P_Name_Text.Value = NC_C_L.Cells(nRow, 20)
Me.P_PhoneNumber_Text.Value = NC_C_L.Cells(nRow, 21)
Me.P_Address_Text.Value = NC_C_L.Cells(nRow, 22)
End Sub
(我做了修改一些名稱,以反映***。)
有什麼''***? – BruceWayne
您的代碼可以從* NC_C_L表中讀取*(無論如何)。如果您想「更新」該工作表的內容,則需要將*寫入*的代碼。這幾乎就像閱讀,除了你翻轉作業的方向,例如'NC_C_L.Cells(nRow,22)= Me.P_Address_Text.Value'。你在問什麼? –
我改變了一些我的實際文本,以反映***只是爲了隱私/安全等 –