【问题标题】:Copy & paste special that is transposing values to paste on the next available row of another sheet复制和粘贴特殊值,即转置值以粘贴到另一个工作表的下一个可用行
【发布时间】:2022-06-13 11:45:19
【问题描述】:

我需要

  • 从我的“Scrubber”表中的 M 列复制数据
  • 张贴到我的“案例日志”表上的下一个打开的行(在这种情况下,它将是金色的第 3 行,但每次都需要这个到下一行)
  • 清除我的“Scrubber”工作表数据 (A:D)
Sub CCRS()
    Range("M2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Case Log").Select
    Range("F4").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
      :=False, Transpose:=True
    Sheets("Daily Scrubber").Select
    ActiveWindow.SmallScroll Down:=-63
    Range("D2").Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.ClearContents
End Sub

案例记录表

洗涤纸

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    复制-转置列范围

    Option Explicit
    
    Sub CCRS()
        
        ' Source
        Const sName As String = "Daily Scrubber"
        Const sCopyFirstCellAddress As String = "M2" ' column
        Const sClearFirstCellAddress As String = "A2"
        Const sClearColumnsCount As Long = 4
        ' Destination
        Const dName As String = "Case Log"
        Const dFirstCellAddress As String = "F2" ' row
        ' Both
        Const DataSize As Long = 7
        Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
        
        Dim sCopyData As Variant
        Dim rng As Range
        
        ' Source
        With wb.Worksheets(sName)
            sCopyData = .Range(sCopyFirstCellAddress).Resize(DataSize).Value ' data
            Set rng = .Range(sClearFirstCellAddress) ' first cell
            With rng.CurrentRegion ' clear data (without headers)
                rng.Resize(.Row + .Rows.Count - rng.Row, .Column + .Columns.Count _
                    - rng.Column).Resize(, sClearColumnsCount).ClearContents
            End With
        End With
        
        ' Destination
        With wb.Worksheets(dName)
            With .Range(dFirstCellAddress).Resize(, DataSize) ' first row
                Set rng = .Resize(.Worksheet.Rows.Count - .Row + 1) _
                    .Find("*", , xlFormulas, , xlByRows, xlPrevious) ' last cell
                If rng Is Nothing Then
                    Set rng = .Cells ' no data (no last cell); use first row
                Else
                    Set rng = .Offset(rng.Row - .Row + 1) ' first empty row range
                End If
            End With
            rng.Value = Application.Transpose(sCopyData) ' write
        End With
        
        MsgBox "Column copy-transposed.", vbInformation
        
    End Sub
    

    【讨论】:

    • 谢谢!!!这非常有效,而且很容易理解!
    • 我刚刚纠正了一个错误(与.Resize(, sClearColumnsCount) 有关的错误)。现在再复制一次。对不起。
    • 我想回来只是说声谢谢——你不知道我有多感激!
    猜你喜欢
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多