从其他多个表中复制大量信息 [英] Copying large amounts of information from multiple other sheets

查看:82
本文介绍了从其他多个表中复制大量信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是将来自多张纸的信息全部合并为一张纸.我看过SO上的其他帖子,但它们似乎对我没有用.我试图做这样的事情:

What I'm trying to do is combine information from multiple sheets all into one sheet. I've seen other posts on SO but they don't seem to work for me. I tried making something like this:

Sub Copy_Data()
    Dim empt As Long
    Dim emptmas As Long

    For s = 2 To 8
        Set ws = Worksheets(2)
        For col = 1 To 25
            For row = 2 To 51

            empt = Worksheets(1).Cells(1, Columns.Count).End(xlToLeft).Select
            emptmas = empt + 1

            Worksheets(1).Cells(row, col).Value = Worksheets(s).Cells(emptmas, col).Value

            Next row
        Next col
    Next s

End Sub

但是当我运行代码时什么也没有发生,甚至没有错误.我尝试只运行:

But nothing happens when I run the code, not even an error. I tried running just:

Worksheets(1).Cells(1, 1).Value = Worksheets(2).Cells(1, 1).Value

但是即使那样也没做任何事情.不能使用Cells()函数从另一张纸复制吗?

But even that didn't do anything. Is it not possible to use the Cells() function to copy from another sheet?

推荐答案

未经测试,但是我认为这是您追求的目标

Not tested, but I think this is what you're after:

Sub MacroMan()

Dim lastCell As Excel.Range

For i = 2 To 8
    With Sheets(i)    
        Set lastCell = .Cells.Find(What:="*", After:=.Cells(2, 1), Lookat:=xlPart, _
            LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
            MatchCase:=False)

        If Not lastCell Is Nothing Then 
            .Range(Cells(2, 1), lastCell).Copy Destination:=Sheets(1).Range("A" & _
                Sheets(1).Rows.Count).End(xlUp).Offset(1, 0)
        End If
    End With
Next i

End Sub

这篇关于从其他多个表中复制大量信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆