【发布时间】:2021-02-19 14:55:35
【问题描述】:
我在尝试为列表中的新项目编号并在同一行中为相关列填充相关默认值时遇到了一个问题。如果单元格已经填充了数据,我不希望其他列中的单元格发生变化。即,如果目标列中的目标单元格中有信息并且有人编辑了信息,我不希望它删除该行其他列中的信息。
我已经编写了以下代码来实现这一点,但我不确定如何检查目标单元格中是否已经有文本,因为我尝试过的方法不起作用(如果 IsEmpty(Target.Value) = True Then)。
If IsEmpty(Target.Value) = True Then
Dim Description_Column_No As Integer
Dim Default_Start As String
'Inputs
Default_Start = "N/A"
Description_Column_No = 3
'Output Columns
Output_Col_Item = Description_Column_No - 1
Output_Col_1 = Description_Column_No + 6
Output_Col_2 = Description_Column_No + 18
Output_Col_3 = Description_Column_No + 28
Output_Col_4 = Description_Column_No + 38
Output_Col_5 = Description_Column_No + 44
Output_Col_6 = Description_Column_No + 55
Output_Col_7 = Description_Column_No + 62
'Adding the date to the relevant cell
'Setting the Item Number for the new Item
With _
Target(Target.Row, Output_Col_Item).Value = Target.Row - 5
End With
'Setting the dropdowns to default values
With _
Target(Target.Row, Output_Col_1).Value = Default_Start
End With
With _
Target(Target.Row, Output_Col_2).Value = Default_Start
End With
With _
Target(Target.Row, Output_Col_3).Value = Default_Start
End With
With _
Target(Target.Row, Output_Col_4).Value = Default_Start
End With
With _
Target(Target.Row, Output_Col_5).Value = Default_Start
End With
With _
Target(Target.Row, Output_Col_6).Value = Default_Start
End With
With _
Target(Target.Row, Output_Col_7).Value = Default_Start
End With
End If
【问题讨论】:
-
可能在行中的其他单元格上使用
IsEmpty,而不是Target。 -
我想对其进行设置,以便用户只需输入项目的名称,然后自动为其分配一个数字并填充默认列。所以它实际上只是我想要应用代码的那个单元格。
-
"如果单元格中已经填充了数据,我不希望其他列中的单元格发生变化。"... 然后你必须检查 other 单元格在修改它们之前。
-
好主意!我试过: If IsEmpty(Me.Range(Status_Col_2 & Target.Row)) = True 或 IsEmpty(Me.Range(Status_Col_2 & Target.Row)) = True 然后
-
您的 With 块的结构都很奇怪,因此这可能是问题的一部分 - 块没有内容,因为行继续使“内容”成为
With的一部分