excel 自动激活单元值和偏移功能

ff29svar  于 2023-01-27  发布在  其他
关注(0)|答案(2)|浏览(120)

'请帮助我使用输入功能自动执行下面的代码,这样我就可以在输入框中键入数字,以自动填充所需的行。'

sub DAY()
GENERAL Macro

ActiveCell.Value = "DAY"

Select Case ActiveCell.Value

Case "DAY"
    ActiveCell.Resize(, 1).Value = "DAY"
    ActiveCell.Offset(, 1).Value = "OFF"
    ActiveCell.Offset(, 2).Value = "DAY"
    ActiveCell.Offset(, 3).Value = "OFF"
    ActiveCell.Offset(, 4).Value = "DAY"
    ActiveCell.Offset(, 5).Value = "OFF"
    ActiveCell.Offset(, 6).Value = "DAY"
    ActiveCell.Offset(, 7).Value = "OFF"
    ActiveCell.Offset(, 8).Value = "DAY"
    ActiveCell.Offset(, 9).Value = "OFF"
    ActiveCell.Offset(, 10).Value = "DAY"
    ActiveCell.Offset(, 11).Value = "OFF"
    ActiveCell.Offset(, 12).Value = "DAY"
    ActiveCell.Offset(, 13).Value = "OFF"

 End Select

 End Sub

'请帮助我使用输入功能自动执行下面的代码,这样我就可以在输入框中键入数字,以自动填充所需的行。'

0h4hbjxa

0h4hbjxa1#

我想你可能想要这样的东西?

Sub PopulateListByRows()
    Dim n As Long, a As Long, ArrTxt
    n = InputBox("How many days?")
    ArrTxt = Array("Day", "Off")
    For a = 1 To n
        ActiveCell.Offset(a - 1).Value = ArrTxt((a + 1) Mod 2)
    Next
End Sub

Sub PopulateListByColumns()
    Dim n As Long, a As Long, ArrTxt
    n = InputBox("How many days?")
    ArrTxt = Array("Day", "Off")
    For a = 1 To n
        ActiveCell.Offset(0, a - 1).Value = ArrTxt((a + 1) Mod 2)
    Next
End Sub
yk9xbfzb

yk9xbfzb2#

你可以用公式

Sub Day()
    Dim n As Long
    n = CLng(InputBox("How many days?"))
    With ActiveCell.Resize(1, 2 * n)
        .FormulaR1C1 = "=IF(RC[-1]=""DAY"",""OFF"",""DAY"")"
        .Value = .Value
    End With
End Sub

相关问题