我有一个工作表,有4个表,我使用用户表单输入数据到每个表,但我需要知道如何编辑数据在特定的表不指列A或B……我想指的是表名和标题名称的表
此示例用于将数据添加到表中
Dim cellrange As String
Dim rowno As Integer
Dim AddFood As ListObject
Dim AddBev As ListObject
Dim AddOther As ListObject
Set AddFood = Data.ListObjects("T_Food")
Set AddBev = Data.ListObjects("T_Beverage")
Set AddOther = Data.ListObjects("T_Other")
Dim AddedRow As ListRow
If txtCode.Text = "" Or comDepartment.Text = "" Or txtItemName.Text = "" Or comUnit.Text = "" _
Or txtPrice.Text = "" Or TxtSalePrice.Text = "" Then
Beep
MsgBox " Please Enter Data "
Exit Sub
如果结束
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'''''''''''''''''''''''
Set Da = Data
Set ww = Application.WorksheetFunction
With Da
If Me.comDepartment = "Food" Then
cname = Me.txtItemName.Text
fc = ww.CountIf(Data.Range("T_Food[[Item Name]]"), cname)
If fc >= 1 Then
amedia = MsgBox(" This name already exists ", vbCritical, "Inventory Program")
Exit Sub
如果结束
Set AddedRow = AddFood.ListRows.Add()
With AddedRow
AddedRow.Range(1) = Me.txtCode.Text 'Code
AddedRow.Range(2) = Me.txtItemName.Text 'name
AddedRow.Range(3) = Me.txtCode.Text
AddedRow.Range(4) = Me.comUnit.Text 'Unit
AddedRow.Range(5) = Me.txtPrice.Text 'CostPrice
AddedRow.Range(6) = Me.TxtSalePrice.Text
AddedRow.Range(8) = Me.comDepartment.Text 'Department
1条答案
按热度按时间kgsdhlau1#
任何Excel行的任何单元格(
Range
)(即使是ListRow
)都有Row
属性,该属性为1,Column
属性应递增以获得以下属性。因此,请尝试理解下一个代码并应用其含义:编辑:
请尝试理解/使用下一种方法来更改表
DataBodyRange
中的任何值。如果更方便,您可以直接使用该数字,而不是使用其Header提取列号:请在测试后发送一些反馈。