首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Excel VBA宏崩溃Excel

Excel VBA宏崩溃Excel
EN

Stack Overflow用户
提问于 2022-06-23 17:27:28
回答 1查看 61关注 0票数 0

我已经创建了一个宏与一些帮助这个网站的优秀人员,以确定是否在这个excel中的列被填充,然后分离他们为一个更大的项目。我的问题是,代码只是崩溃(加载,直到我点击,在其中我被告知excel是没有响应的) excel。我能得到一些帮助吗

代码语言:javascript
复制
Option Explicit

Public Sub emptysinder()

    Dim i As Long
    Dim r As Range
    Dim num As Integer
    
    For i = 1 To 9
        Set r = Range("F1").Offset(0, i - 1).Resize(200, 1)
        If IsAllEmpty(r) Then
            num = num + 1
            Debug.Print "Range " & r.Address & " is all empty." & num
        ElseIf IsAnyEmpty(r) Then
            Debug.Print "Range " & r.Address & " is partially empty."
        Else
            Debug.Print "Range " & r.Address & " filled."
        End If
    Next i
    split (num)

End Sub

Public Function IsAllEmpty(ByVal r_range As Range) As Boolean
    Dim Item As Range
    For Each Item In r_range
        If Not IsEmpty(Item) Then
            IsAllEmpty = False
            Exit Function
        End If
    Next
    IsAllEmpty = True
End Function

Public Function IsAnyEmpty(ByVal r_range As Range) As Boolean
    Dim Item As Range
    For Each Item In r_range
        If IsEmpty(Item) Then
            IsAnyEmpty = True
            Exit Function
        End If
    Next
    IsAnyEmpty = False
End Function
Public Function split(i As Integer)
    Dim sheet As Integer
    Dim colOpt As Integer
    sheet = 14
    colOpt = sheet - i
    Dim s As Integer
    Do While i > 0
        For s = 4 To 0
        Columns(colOpt).Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        i = i - 1
        Next s
    Loop
End Function
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-23 18:34:56

如前所述,拆分函数中的for循环没有执行,因为s值是递增的,而不是递减的。每次迭代时使用For s = 4 To 0 Step -1将s减少1。

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

https://stackoverflow.com/questions/72734303

复制
相关文章

相似问题

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