我正在尝试合并前三个空行并在三个合并单元格中写入Activity#。我甚至无法弄清楚如何选择3个自定义单元格来准备合并。我在网上到处检查但是范围(A1:B2)总是给出一个确定的范围。我如何编写例如:range(variable_A1:variable_B2)?
到目前为止,这是我的代码:
Private Sub OKButton_Click()
'Make Sheet1 active
Sheet1.Activate
Dim beginning
Dim ending
Dim selection
beginning = Cells(empty_row.Value, 2)
ending = Cells(empty_row.Value + 2, 2)
'this is supposed to select 3 cells, but it doesn't work
selection = Range("beginning:ending").Select
'figure out how to merge cells below
Cells(empty_row.Value, 2).Value = "Activity" & Activity_number.Value
Dim i As Integer
For i = 1 To nb_subs.Value
Cells(empty_row.Value + i + 2, 2).Value = "Sub-Activity" & i
Next i
答案 0 :(得分:0)
Private Sub OKButton_Click()
Dim beginning As Range
Dim ending As Range
Dim selection As Range
With Sheet1
Set beginning = .Cells(empty_row.Value, 2)
Set ending = .Cells(empty_row.Value + 2, 2)
'this is supposed to select 3 cells, but it doesn't work
Set selection = .Range(beginning, ending)
selection.Merge
selection.Value = "Activity" & Activity_number.Value
Dim i As Integer
For i = 1 To nb_subs.Value
.Cells(empty_row.Value + i + 2, 2).Value = "Sub-Activity" & i
Next i
End With