Vba 宏行和列复制

Vba 宏行和列复制,vba,excel,Vba,Excel,正在努力让我的头脑了解这个宏以及为什么它不起作用 我找到了其他人,每次我尝试编辑它时,它都会返回到Debug 其目的是将第1页表格中的C行复制到下一行,但我希望它从上面复制I:J和K:L列的信息 另外,当在“顾问周”复制并插入列时,代码中包含了我想要隐藏的列,因此在隐藏列时运行时,它无法正常工作 Dim Lr As Integer Dim AWFr As Long, AWLc As Long AWFr = 14 Lr = Range("C" & Rows.Count).End(xlU

正在努力让我的头脑了解这个宏以及为什么它不起作用

我找到了其他人,每次我尝试编辑它时,它都会返回到Debug

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

另外,当在“顾问周”复制并插入列时,代码中包含了我想要隐藏的列,因此在隐藏列时运行时,它无法正常工作

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

如果需要,我可以很高兴地发送图像,但没有足够的代表在这里发布

这不是答案。我会在评论中问我的问题,除非我已经记录了你的宏,并想分享结果。我也许应该用修改后的宏更新您的问题,但我决定最好将其分开

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

你说的是“I:J和K:L列”而不是“I:L列”?这有什么意义

在我的实验中,隐藏列的存在并没有什么不同

很抱歉,我不知道这意味着什么:“其目的是将第1页表中的C行复制到下一行,但我希望它从上面复制I: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

我试图理解这段代码,但我真的不明白你想做什么。您在哪一行上出错?