【发布时间】:2022-01-09 03:46:03
【问题描述】:
我是 VBA 新手,因此尝试执行此代码时,我能够在我想要的行中运行代码,但我也想为下 2 行运行代码,但不知道如何应用逻辑去下一个可用行。因为我想在同一日期复制数据 3 次。按钮点击后生成的代码如下。
添加其他信息:感谢大家的投入和时间,非常感谢您的帮助。
这很棒,但是我学到了新东西,因为我每天更新 3 次读取的数据,所以我想从我每天更新 3 次的行中复制我的阅读数据,所以为了跟踪目的,我想根据数据将读取数据复制到下面的行。
点击阅读数据应复制到上午、下午和晚上阅读的行,如您从此处的示例图像中看到的示例格式
我希望我能够解释我的问题,因为我不是技术人员,而是尽我所能。
感谢您的帮助。
Private Sub CommandButton1_Click()
Dim Rg As Range
Set Rg = Me.UsedRange.Columns(1).Find(Application.Text(Date, [A16].NumberFormat), [A17], xlValues)
If Rg Is Nothing Then MsgBox "Today's Date Not Found. Please check the 'Date Received'" Else Rg(1, 2).Resize(, 24).Value2 = [B16:W16].Value2: Set Rg = Nothing
' If Rg Is Nothing Then MsgBox "Today's Date Not Found. Please check the 'Date Received'" Else Rg(2, 2).Resize(, 24).Value2 = [B16:W16].Value2: Set Rg = Nothing
' If Rg Is Nothing Then MsgBox "Today's Date Not Found. Please check the 'Date Received'" Else Rg(3, 2).Resize(, 24).Value2 = [B16:W16].Value2: Set Rg = Nothing
End Sub
【问题讨论】:
-
尝试使用
Offsetmethod的范围,如Rg.Offset。 -
如果可能的话,最好在多行上编写代码 - 将
If Then Else放在一行上(然后再写一个语句)会更难理解。 -
我试过了,但对我没用。
-
对我有什么帮助..?