excel - 复制和粘贴特殊值,即转置值以粘贴到另一个工作表的下一个可用行

标签 excel vba

我需要

  • 从我的“Scrubber”表中的 M 列复制数据
  • 在下一个打开的行上发布到我的“案例日志”表(在这种情况下,它将是金色的第 3 行,但每次都需要这个去下一行)
  • 清除我的“洗涤器”工作表数据 (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
    
    案例记录表
    enter image description here
    洗涤板
    enter image description here

    最佳答案

    复制转置列范围

    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
    

    关于excel - 复制和粘贴特殊值,即转置值以粘贴到另一个工作表的下一个可用行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71542527/

    相关文章:

    vba - 如何使用 VBA 播放波形文件或声音文件

    vba - 使用 VBA 填充 Excel 表单中的动态下拉列表

    excel - Excel : comparing list of user permissions with pairs of disallowed roles 中的角色/权限分析

    excel - 通配符所选电子表格名称上的 AVERAGEIF 函数

    excel - 希望返回给定公司名称的行的最大值

    excel - 如何在 Excel 中的文本文件中搜索特定行

    excel - 如何用VBA编写方程

    arrays - 在 VBA 函数中从范围切换到数组并返回

    excel - 从 Excel 发送邮件 - 运行时错误 '429' : ActiveX component can't create object

    php - 如何下载包含 HTML 标签的 csv 文件