首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >rows.cut的VBA型失配

rows.cut的VBA型失配
EN

Stack Overflow用户
提问于 2020-02-19 12:20:41
回答 1查看 34关注 0票数 0

我在切割多张工作表并把它放在一个表上有问题。我得到了“类型错配”错误。你能看看我的密码吗?

代码语言:javascript
运行
复制
Public Sub Conc()
Dim ws  As Worksheet
Dim LR1 As Integer
Dim LR2 As Integer
Dim LR3 As Integer
Dim first As Integer
LR1 = 0
LR2 = 0
LR3 = 0
first = 1
With ThisWorkbook
    .Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = "Conc"
End With

For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Conc" Then
        LR1 = Sheets("Conc").Cells(Rows.Count, 2).End(xlUp).Row + 1
        LR2 = ws.Cells(Rows.Count, 2).End(xlUp).Row
        LR3 = LR1 + LR2
        Worksheets(ws).Rows(first & ":" & LR2).Cut
        Worksheets("Conc").Rows(LR1 & ":" & LR3).Insert
    End If
Next ws
End Sub
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-19 12:44:44

尝试:

代码语言:javascript
运行
复制
Public Sub Conc()

    Dim ws  As Worksheet
    Dim LR1 As Long, LR2 As Log, LR3 As Long
    Dim first As Integer

    LR1 = 0
    LR2 = 0
    LR3 = 0
    first = 1

    With ThisWorkbook
        .Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = "Conc"
    End With

    With ThisWorkbook.Worksheets("Conc")
        LR1 = .Cells(.Rows.Count, 2).End(xlUp).Row + 1
    End With

    For Each ws In ActiveWorkbook.Worksheets

        If ws.Name <> "Conc" Then

            With ws

                LR2 = .Cells(.Rows.Count, 2).End(xlUp).Row
                LR3 = LR1 + LR2
                .Rows(first & ":" & LR2).Cut
            End With

            ThisWorkbook.Worksheets("Conc").Rows(LR1 & ":" & LR3).Insert

        End If

    Next ws

End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60300266

复制
相关文章

相似问题

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