添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
帅气的山羊  ·  With statement (VBA) ...·  3 周前    · 
爱运动的毛豆  ·  Excel剪贴板清除 - ·  1 周前    · 
大方的柚子  ·  Excel VBA ...·  1 周前    · 
爱看球的毛豆  ·  使用 Spring Boot Admin ...·  9 月前    · 
乖乖的皮带  ·  A-Z Databases·  10 月前    · 
会开车的西装  ·  Home | Viver·  10 月前    · 
读研的橙子  ·  楚楚by笼中月? - 知乎·  1 年前    · 
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excel VBA 将其他表的范围的值按顺序填入插入;清除剪贴板

Posted at

将其他表的范围的值按顺序填入插入,并涉及清除剪贴板
该示例将Date表里面L2到L25范围的值,按顺序插入到计算表的D列。
具体动作为:首先取得Date表中L2到L25的范围值,
之后将范围值用For Each循环,并从第2行开始,逐行复制计算表里面的每行的值,
然后将循环到的Date表里面的值写入到被复制的D列
最后的时候删除多复制的一行即可,删除时清楚剪切版的内容,释放空间(感觉然并卵)

为了防止程序卡住,可以以每执行2000行打印一条数据看一看,这样就能知道是否程序还在工作(被注释掉的 If i Mod 2000 = 0 的部分)

Sub InsertData()
    i = 2
    Dim wsDate As Worksheet
    Set wsDate = ThisWorkbook.Worksheets("Date")
    Data0s = wsDate.Range("L2:L25").Value
    col = "D"
    '画面更新暂停
    Application.ScreenUpdating = False
        For Each Data0 In Data0s
            Rows(i + 1).Insert shift:=xlShiftDown
            Range(Cells(i, "A"), Cells(i, "G")).Copy
            Cells(i + 1, 1).PasteSpecial
            Cells(i, col) = Data0
            i = i + 1
        Next Data0
        Rows(i).Delete
    	'清除剪切板内容
        Application.CutCopyMode = False
        DoEvents
        Debug.Print i
'        If i Mod 2000 = 0 Then
'            Debug.Print i
'        End If
    Loop While Cells(i, "A") <> ""
    '画面更新恢复
    Application.ScreenUpdating = True
    End Sub
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?