这段代码为下面定义的行数复制第2行和第3行。如果我希望第2行的大小等于excel中所有偶数行的大小,而第3行的大小等于excel中除第1行以外的所有奇数行,该如何更改代码。
Sub Macro2()
Dim rRange As Range
Set rRange = Selection.Rows("2:3")
Dim n As Integer
Dim Rng As Integer
n = rRange.Rows.Count
Rng = InputBox("Enter number of sessions: ")
Dim i As Integer
Rows("2:3").Copy
For i = 1 To Rng
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveSheet.Paste
Next i
End Sub
发布于 2020-05-12 19:43:37
调整行高和列宽可以如以下示例所示:
Columns("A:A").ColumnWidth = 15.43
Rows("1:1").RowHeight = 34.5
祝好运
发布于 2020-05-12 19:57:42
你应该避免使用Select
,正如塞缪尔所说的那样,给一行赋予高度很容易,困难的部分将是确定选择哪个高度。有了你提供的信息,只要你给X
和Y
一个值,就可以做到:
Option Explicit
Sub Test()
Dim n As Long: n = InputBox("Enter number of sessions: ")
'assume you have a sheet called SheetWithNames where you input the worksheet where you are
'going to work, and that name is written in cell A1, then this line below would take that name.
Dim SheetName As String: SheetName = ThisWorkbook.Sheets("SheetWithSheetNames").Range("A1")
With ThisWorkbook.Sheets(SheetName) 'Change SheetName for your sheet name
'This will take the first available row if all your rows in column A are filled
Dim i As Long
For i = 1 To n
.Cells(.Rows.Count, 1).End(xlUp).Offset(1).Resize(2).EntireRow.Value = .Rows("2:3").Value
Next i
n = .Cells(.Rows.Count, 1).End(xlUp).Row
.Rows("2:" & n).RowHeight = 118
End With
End Sub
https://stackoverflow.com/questions/61750667
复制相似问题