【发布时间】:2017-01-07 20:53:45
【问题描述】:
我有一个数据库和一个表单来输入数据。该表单正在将数据添加到表中的下一个空行。我的表单中有 4 个选项按钮,指示下一个条目是哪种类型的交易。我想根据选择的选项按钮格式化 B 列中单元格的背景,因此当我单击确认时,表单中的数据将插入数据库中,并且 B 列中单元格的背景颜色设置正确。我无法从该设备上传我的代码,但实际上背景颜色已设置但始终相同,并且如果我选择其他选项按钮也不会更改。
知道可能是什么问题吗?在应用选项按钮之前,我是否需要包含一行来清除以前的格式?
Private Sub CommandButton1_Click()
Dim L As Integer
Dim Code As String
If MsgBox("Confirm?", vbYesNo, "Confirming new invoice") = vbYes Then
L = Sheets("FACTURE").Range("D65535").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement _ la premi_re ligne de tableau non vide
Range("C" & L).Value = (Now)
Range("D" & L).Value = TextBox2
Range("E" & L).Value = TextBox3
Range("F" & L).Value = TextBox4
Range("G" & L).Value = TextBox5
Range("K" & L).Value = ComboBox1
Range("L" & L).Value = ComboBox2
Range("M" & L).Value = ComboBox3
Range("N" & L).Value = TextBox9
Range("O" & L).Value = TextBox10
Range("R" & L).Value = TextBox39
Range("P" & L).Value = TextBox40
End If
If OptionButton1.Enabled = True Then
Range("B" & L).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
ElseIf OptionButton2.Enabled = True Then
Range("B" & L).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
End If
End Sub
【问题讨论】:
-
您使用的是 VBA 用户窗体还是工作表 ActiveX 的? 数据库究竟是什么?
-
我使用 VBA 表单,数据库是工作表中的表
-
请上传相关代码
-
我在问题中添加了代码
标签: excel forms vba colors format