宏行和列复制

时间:2015-01-27 22:14:44

标签: excel vba excel-vba

挣扎着绕过这个宏,为什么它不起作用。

我已经接过其他人,每当我尝试编辑它时,它都会回到De-Bug。

目的是将表1,行C上的表格中的行复制到下一行 - 但我希望它从上面复制第I列的信息:J和K:L。

此外,当复制并插入“Advisor周”列时,代码已经包含了我想要隐藏的列,因此当隐藏列时运行时,它无法正常工作。 / p>

Dim Lr As Integer
Dim AWFr As Long, AWLc As Long

AWFr = 14

Lr = Range("C" & Rows.Count).End(xlUp).Row
Rows(Lr + 1).Insert Shift:=xlDown
Cells(Lr + 1, "C") = Cells(Lr, "C") + 1
Rows(Lr).Copy
Rows(Lr + 1).PasteSpecial Paste:=xlPasteFormats

With Worksheets("Advisor Week")

    AWLc = .Cells(AWFr, .Columns.Count).End(xlToLeft).Column
    .Cells(AWFr, AWLc - 5).Resize(, 5).EntireColumn.Insert Shift:=xlToLeft
    .Columns(AWLc - 5).ColumnWidth = 0.5
    .Columns(AWLc - 9).Resize(, 5).Copy Destination:=.Columns(AWLc - 4)
    Application.CutCopyMode = False

End With

如果需要,我可以愉快地发送图片,但没有足够的Rep在这里发布

1 个答案:

答案 0 :(得分:0)

这不是答案。我会在评论中提出我的问题,除了我已经记录了你的宏并希望分享结果。我或许应该用修改后的宏更新你的问题但是已经决定最好把它分开。

在尝试修改继承的代码之前,我确保确切地知道它的作用。如有必要,我将逐步逐句陈述并记录每份陈述。像D_Zab一样,我不明白这个代码是在尝试什么。这是原始代码还是部分修改?

你说“第一栏:J和K:L”而不是“第一栏:L”?这有什么意义?

在我的实验中,隐藏列的存在并没有什么区别。

我很抱歉,但我不知道这意味着什么:“目的是将第1页,第C行表格中的行复制到下一行 - 但我希望它能从上面复制信息第一栏:J和K:L。“

Option Explicit
Sub Test()

  Dim Lr As Integer
  Dim AWFr As Long, AWLc As Long

  AWFr = 14

  ' Find last used row in column C of active worksheet
  Lr = Range("C" & Rows.Count).End(xlUp).Row

  ' Insert row below last row in column C of active worksheet. If other
  ' columns have values below the last used row in C, those values will
  ' be moved down one row. The formatting (except borders) of the last
  ' used row in C is copied to the inserted row.
  Rows(Lr + 1).Insert Shift:=xlDown

  ' Add 1 to last cell in column C of active worksheet and store in
  ' next row down.
  Cells(Lr + 1, "C") = Cells(Lr, "C") + 1

  ' Copy formats (including borders) from last row with a value
  ' in column C of active worksheet to next row down.
  Rows(Lr).Copy
  Rows(Lr + 1).PasteSpecial Paste:=xlPasteFormats

  With Worksheets("Advisor Week")

    ' Find last used column in row 14
    AWLc = .Cells(AWFr, .Columns.Count).End(xlToLeft).Column

    ' Insert columns to move last used column in row 14, and the four
    ' columns to its left, to the right
    .Cells(AWFr, AWLc - 5).Resize(, 5).EntireColumn.Insert Shift:=xlToLeft

    ' Set column width of first new column to half the width of character "0"
    ' which is 7 pixels with Tahoma 10.5.
    .Columns(AWLc - 5).ColumnWidth = 0.5

    ' Copy the four columns to the left of the inserted columns, and the
    ' first inserted (narrow) column, over the last four inserted columns
    ' and the first column that was shifted right
    .Columns(AWLc - 9).Resize(, 5).Copy Destination:=.Columns(AWLc - 4)

    Application.CutCopyMode = False

  End With

End Sub
相关问题