Excel精英培训网

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

[已解决]求助对VBA代码的修正

[复制链接]
发表于 2015-8-15 14:44 | 显示全部楼层 |阅读模式
本帖最后由 安全网 于 2015-8-15 16:14 编辑

Private Sub CommandButton1_Click()
On Error Resume Next
    If Len(ListBox3) > 0 Then   ' 如果文字框有文字
    Sheets("刨花板").Select
        Sheets("刨花板").[h1] = ListBox3.Text
        If WorksheetFunction.CountIf(Sheets("刨花板").Range("H:H"), [h1].Value) < 2 Then
        Sheets("sheet1").Select
        UserForm1.Show 0
        UserForm1.ListBox3 = ""
        Else
        [h1].Select
        Sheets("刨花板").Cells.Find(What:=[h1], After:=ActiveCell).Activate
       ActiveCell.Offset(0, 1).Select
       ActiveCell.EntireRow.Select
       Selection.Copy
    Sheets("Sheet1").Select
     Selection.Insert Shift:=xlUp
     Call CycleThrough
     End If
     End If
End Sub
以上代码在WPS内可以运行,但是在OFFICE2003内就复制不了数据,请各位帮忙修正一下
最佳答案
2015-8-15 15:30
本帖最后由 zjdh 于 2015-8-15 15:47 编辑

Private Sub CommandButton1_Click()
    If Len(ListBox3) > 0 Then
        With Sheets("刨花板")
            If WorksheetFunction.CountIf(.[H:H], ListBox3) < 1 Then
                ListBox3.Clear
            Else
                Set W = .[H:H].Find(ListBox3)
                W.EntireRow.Copy
                Rows(Selection.Row).Insert
                Call CycleThrough
            End If
        End With
    End If
End Sub

book10815.rar

142.86 KB, 下载次数: 2

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-8-15 15:30 | 显示全部楼层    本楼为最佳答案   
本帖最后由 zjdh 于 2015-8-15 15:47 编辑

Private Sub CommandButton1_Click()
    If Len(ListBox3) > 0 Then
        With Sheets("刨花板")
            If WorksheetFunction.CountIf(.[H:H], ListBox3) < 1 Then
                ListBox3.Clear
            Else
                Set W = .[H:H].Find(ListBox3)
                W.EntireRow.Copy
                Rows(Selection.Row).Insert
                Call CycleThrough
            End If
        End With
    End If
End Sub
回复

使用道具 举报

发表于 2015-8-15 15:51 | 显示全部楼层
你要把“刨花板”的H1内容删除!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 04:53 , Processed in 0.282425 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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