Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 5301|回复: 8

[已解决]查找哪个单元格字符多于255个,并选中它?(已解决)

[复制链接]
发表于 2010-3-1 21:30 | 显示全部楼层 |阅读模式
查找下面工作表中,哪个单元格字符多于255个,并选中它?
我的代码都是类型不匹配!!请帮我修改我的代码!谢谢!!

7uJ74HEI.rar (15.28 KB, 下载次数: 7)
发表于 2010-3-1 22:08 | 显示全部楼层

因为有的单元格有公式,试着改一下:

Sub 查找一个单元格字符多于255个()
    Dim TMP As Range
    With Sheets("7.3")
    For Each TMP In .UsedRange
        If Len(TMP.Formula) > 255 Then
            MsgBox TMP.Address(0, 0)
        End If
    Next
    End With
End Sub

回复

使用道具 举报

 楼主| 发表于 2010-3-2 09:25 | 显示全部楼层

QUOTE:
以下是引用枯禅在2010-3-1 22:08:00的发言:

因为有的单元格有公式,试着改一下:

Sub 查找一个单元格字符多于255个()
    Dim TMP As Range
    With Sheets("7.3")
    For Each TMP In .UsedRange
        If Len(TMP.Formula) > 255 Then
            MsgBox TMP.Address(0, 0)
        End If
    Next
    End With
End Sub

QUOTE:
你提供的好用!要是指出我的代码问题怎么解决那就更强了!!!谢谢!!

回复

使用道具 举报

发表于 2010-3-2 10:18 | 显示全部楼层

原工作表公式错误,有错误值,导致运行错误。
回复

使用道具 举报

发表于 2010-3-2 10:27 | 显示全部楼层    本楼为最佳答案   


Sub 查找一个单元格字符多于255个()
    Dim i As Long
    Dim TMP As Range
    Dim Ro As Long
    Dim Col As Integer

    Sheets("7.3").Select
    i = 0
    For Each TMP In Range("A1:iv100")
        i = i + 1
        If Len(TMP.Text) > 255 Then

            Debug.Print Sheets("7.3").Columns.Count
            'Sheets("7.3").Columns.Count是一个常量,直接用256表示就可以了
            Col = i - i Mod Sheets("7.3").Columns.Count
            
'            Ro = IIf(i < Sheets("7.3").Columns.Count, 1, Num \ Sheets("7.3").Columns.Count)
            Ro = IIf(i < Sheets("7.3").Columns.Count, 1, i \ Sheets("7.3").Columns.Count)
            
            Cells(Ro, Col).Select   'col>256,出错
            MsgBox Sheets("7.3").Cells(Ro, Col).Address(0, 0)
        Else
        End If
    Next TMP
End Sub

因为有如上几处小错误,解决后算法上也不对,所以导致出错,无法继续 ...

回复

使用道具 举报

 楼主| 发表于 2010-3-2 19:27 | 显示全部楼层

QUOTE:
以下是引用爱疯在2010-3-2 10:27:00的发言:


Sub 查找一个单元格字符多于255个()
    Dim i As
   Long
    Dim TMP As Range
    Dim Ro As
   Long
    Dim Col As
   Integer

    Sheets("7.3").Select
    i = 0
    For
   Each TMP In Range("A1:iv100")
        i = i + 1
        If Len(TMP.Text) > 255 Then

            Debug.Print Sheets("7.3").Columns.Count
            'Sheets("7.3").Columns.Count是一个常量,直接用256表示就可以了
            Col = i - i Mod Sheets("7.3").Columns.Count
            
'            Ro = IIf(i < Sheets("7.3").Columns.Count, 1, Num \ Sheets("7.3").Columns.Count)
            Ro = IIf(i < Sheets("7.3").Columns.Count, 1, i \ Sheets("7.3").Columns.Count)
            
            Cells(Ro, Col).Select   'col>256,出错
            MsgBox Sheets("7.3").Cells(Ro, Col).Address(0, 0)
        Else
        End
   If
    Next TMP
End
   Sub

因为有如上几处小错误,解决后算法上也不对,所以导致出错,无法继续 ...

谢谢你详细的分析!

在此基础上,我自己做了改动!下面的代码是成功的!!

Sub 查找一个单元格字符多于255个()
    Dim i As Long
    Dim TMP As Range
    Dim Ro As Long
    Dim Col As Integer
    Sheets("7.3").Select
    i = 0
    For Each TMP In Range("A1:iv100")
        i = i + 1
        If Len(TMP.Text) > 255 Then
            Col = (i - 1) Mod 256 + 1
            Ro = IIf(i < 256, 1, i / 256) + 1
            Cells(Ro, Col).Select
            MsgBox Cells(Ro, Col).Address(0, 0)
        Else
        End If
    Next TMP
End Sub

回复

使用道具 举报

发表于 2010-3-3 21:54 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 2013-10-11 20:22 | 显示全部楼层
以下是引用爱疯在2010-3-2 10:27:00的发言:

Sub 查找一个单元格字符多于255个()
    Dim i As
   Long
    Dim TMP As Range
    Dim Ro As
   Long
    Dim Col As
   Integer

    Sheets("7.3").Select
    i = 0
    For
   Each TMP In Range("A1:iv100")
        i = i + 1
        If Len(TMP.Text) > 255 Then

            Debug.Print Sheets("7.3").Columns.Count
            'Sheets("7.3").Columns.Count是一个常量,直接用256表示就可以了
            Col = i - i Mod Sheets("7.3").Columns.Count
            
'            Ro = IIf(i < Sheets("7.3").Columns.Count, 1, Num \ Sheets("7.3").Columns.Count)
            Ro = IIf(i < Sheets("7.3").Columns.Count, 1, i \ Sheets("7.3").Columns.Count)
            
            Cells(Ro, Col).Select   'col>256,出错
            MsgBox Sheets("7.3").Cells(Ro, Col).Address(0, 0)
        Else
        End
   If
    Next TMP
End
   Sub


因为有如上几处小错误,解决后算法上也不对,所以导致出错,无法继续 ...

谢谢你详细的分析!

在此基础上,我自己做了改动!下面的代码是成功的!!

Sub 查找一个单元格字符多于255个()
    Dim i As Long
    Dim TMP As Range
    Dim Ro As Long
    Dim Col As Integer
    Sheets("7.3").Select
    i = 0
    For Each TMP In Range("A1:iv100")
        i = i + 1
        If Len(TMP.Text) > 255 Then
            Col = (i - 1) Mod 256 + 1
            Ro = IIf(i < 256, 1, i / 256) + 1
            Cells(Ro, Col).Select
            MsgBox Cells(Ro, Col).Address(0, 0)
        Else
        End If
    Next TMP
End Sub

回复

使用道具 举报

发表于 2013-10-11 22:30 | 显示全部楼层
学习了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-20 10:58 , Processed in 0.328327 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表