首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将选定的单元格复制并粘贴到整行上,直到上面的列为空

将选定的单元格复制并粘贴到整行上,直到上面的列为空
EN

Stack Overflow用户
提问于 2016-11-11 21:34:10
回答 1查看 332关注 0票数 1

我正在尝试找到一种方法来复制第5行中的活动单元格,并将该值粘贴到该单元格中,直到第4行为空。我有多个图纸名称,并需要为所有的图纸名称做这件事。

代码语言:javascript
运行
复制
With ThisWorkbook.Sheets(SheetName)
    Dim LastColumn As Integer
    Dim c2 As Integer
    c2 = 2
    LastColumn = .UsedRange.Columns.Count
    Do Until IsEmpty(.Cells(4, c2).Value)
        If .Cells(1, c2).Value = MonthSel And .Cells(4, c2).Value = WkSel Then
            .Cells(5, c2).Value = RControl
            .Cells(5, c2).copy
            If .Cells(5, c2).Value <> "" Then
                c2 = c2 + 1
                .Cells(5, c2).Paste
            End If
        End If
    Loop
End With

我正在使用的数据的sample

How to results should look

结果应如何显示应使用第5行中的最新值完全填充第5行

EN

回答 1

Stack Overflow用户

发布于 2016-11-11 22:38:18

根据我想我从你的解释中理解的,我猜这就是你想要的。

代码语言:javascript
运行
复制
   Dim LastColumn As Integer
   Dim c2 As Integer
   Dim SourceCell As Range

    With ThisWorkbook.Sheets(SheetName)
        'get last used column in row 4, ALTHOUGH THIS IS NOT NEEDED IN THIS CODE
        LastColumn = .Cells(4, .Columns.Count).End(xlToLeft).Column

        'loop through rest of the row
        c2 = 2
        Do Until IsEmpty(.Cells(4, c2).Value)
            If .Cells(1, c2).Value = MonthSel And .Cells(4, c2).Value = WkSel Then
                Set SourceCell = .Cells(5, c2)
            End If
            If .Cells(5, c2).Value = "" Then
                'Set the source cell for filling up empty column
                .Cells(5, c2).Value2 = SourceCell.Value2
            End If
            c2 = c2 + 1
        Loop
    End With
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40549130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档