我正在尝试将行高从一个 sheet 复制到另一个 sheet
I am trying to copy row heights from one sheet to another sheet
我正在尝试将行高从 sheet1 复制到 sheet2。但以下代码不起作用。请注意,两个 sheet 上的表格也在不同的行号上。
Call Unhide
With Sheet1
Dim LastRowC23 As Integer
LastRowC23 = Application.WorksheetFunction.Match("CYCLE 1",
.Range("A:A"), 0) - 1
Dim LastRow As Integer
LastRow = .Cells(.Rows.count, "B").End(xlUp).Row
.Range("A3:BD3"), 0)
Dim C1StartCol As Integer
C1StartCol = Application.WorksheetFunction.Match("CYCLE 1",
.Range("A1:BD1"), 0)
Dim C2StartCol As Integer
C2StartCol = Application.WorksheetFunction.Match("CYCLE 2", .Range("A1:BD1"), 0)
Dim LastCol As Integer
LastCol = .Cells(3, .Columns.count).End(xlToLeft).Column
Sheet2.Range("A1:CZ200").Clear
.Range("A1", .Cells(3, C2StartCol - 1)).Copy
Sheet2.Range("A1").PasteSpecial xlPasteAllUsingSourceTheme
Sheet2.Range("A1").PasteSpecial xlPasteColumnWidths
.Range(.Cells(LastRowC23 + 1, 1), .Cells(LastRow - 1, C2StartCol - 1)).Copy
Sheet2.Range("A4").PasteSpecial xlPasteAllUsingSourceTheme
Sheet2.Range("A4").PasteSpecial xlPasteColumnWidths
Dim i As Integer
Dim count As Integer
count = 4
For i = LastRowC23 + 1 To LastRow
.Rows(count).RowHeight = Sheet2.Rows(i).RowHeight
count = count + 1
Next i
Sheet2.Outline.ShowLevels ColumnLevels:=1
End With
下面是针对行高的部分。在这里,我将遍历 sheet 1 部分中的每一行,并使 sheet 2 行高等于 sheet 1 行高。
Dim i As Integer
Dim count As Integer
count = 4
For i = LastRowC23 + 1 To LastRow
.Rows(count).RowHeight = Sheet2.Rows(i).RowHeight
count = count + 1
Next i
您位于引用 sheet1 作为父工作表的 With ... End With 块中。 LastRowC23 和 LastRow 由 sheet1 上的行位置定义。 Count 被任意赋值为 4.
如果你是'making the sheet 2 row heights equal to the sheet 1 row heights',那么你好像什么都用反了
For i = LastRowC23 + 1 To LastRow
Sheet2.Rows(count).RowHeight = .Rows(i).RowHeight
count = count + 1
Next i
我正在尝试将行高从 sheet1 复制到 sheet2。但以下代码不起作用。请注意,两个 sheet 上的表格也在不同的行号上。
Call Unhide
With Sheet1
Dim LastRowC23 As Integer
LastRowC23 = Application.WorksheetFunction.Match("CYCLE 1",
.Range("A:A"), 0) - 1
Dim LastRow As Integer
LastRow = .Cells(.Rows.count, "B").End(xlUp).Row
.Range("A3:BD3"), 0)
Dim C1StartCol As Integer
C1StartCol = Application.WorksheetFunction.Match("CYCLE 1",
.Range("A1:BD1"), 0)
Dim C2StartCol As Integer
C2StartCol = Application.WorksheetFunction.Match("CYCLE 2", .Range("A1:BD1"), 0)
Dim LastCol As Integer
LastCol = .Cells(3, .Columns.count).End(xlToLeft).Column
Sheet2.Range("A1:CZ200").Clear
.Range("A1", .Cells(3, C2StartCol - 1)).Copy
Sheet2.Range("A1").PasteSpecial xlPasteAllUsingSourceTheme
Sheet2.Range("A1").PasteSpecial xlPasteColumnWidths
.Range(.Cells(LastRowC23 + 1, 1), .Cells(LastRow - 1, C2StartCol - 1)).Copy
Sheet2.Range("A4").PasteSpecial xlPasteAllUsingSourceTheme
Sheet2.Range("A4").PasteSpecial xlPasteColumnWidths
Dim i As Integer
Dim count As Integer
count = 4
For i = LastRowC23 + 1 To LastRow
.Rows(count).RowHeight = Sheet2.Rows(i).RowHeight
count = count + 1
Next i
Sheet2.Outline.ShowLevels ColumnLevels:=1
End With
下面是针对行高的部分。在这里,我将遍历 sheet 1 部分中的每一行,并使 sheet 2 行高等于 sheet 1 行高。
Dim i As Integer
Dim count As Integer
count = 4
For i = LastRowC23 + 1 To LastRow
.Rows(count).RowHeight = Sheet2.Rows(i).RowHeight
count = count + 1
Next i
您位于引用 sheet1 作为父工作表的 With ... End With 块中。 LastRowC23 和 LastRow 由 sheet1 上的行位置定义。 Count 被任意赋值为 4.
如果你是'making the sheet 2 row heights equal to the sheet 1 row heights',那么你好像什么都用反了
For i = LastRowC23 + 1 To LastRow
Sheet2.Rows(count).RowHeight = .Rows(i).RowHeight
count = count + 1
Next i