Excel精英培训网

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

[已解决]如何根据文本框内容删除该行并复制到sheet1

[复制链接]
发表于 2013-7-21 19:20 | 显示全部楼层 |阅读模式
如何根据文本框内容删除该行并复制到sheet1
最佳答案
2013-7-21 20:45
  1. Private Sub CommandButton1_Click()
  2.     Dim rg As Range
  3.     On Error Resume Next
  4.     If Len(Me.TextBox1) Then
  5.         Set rg = Range("a:a").Find(what:=Me.TextBox1, lookat:=xlWhole)
  6.         If rg Is Nothing Then
  7.             MsgBox "单号 " & Me.TextBox1.Value & " 有误"
  8.             Me.TextBox1.Value = ""
  9.             Me.TextBox1.SetFocus
  10.         Else
  11.             With rg
  12.                 .Resize(, 8).Copy Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1)
  13.                 .EntireRow.Delete
  14.             End With
  15.         End If
  16.     Else
  17.         MsgBox "请输入单号后再进行操作"
  18.         Me.TextBox1.SetFocus
  19.     End If
  20. End Sub
复制代码

示例.zip

9.34 KB, 下载次数: 7

发表于 2013-7-21 20:38 | 显示全部楼层
先查找单号,找到后再复制,然后再删除
或者先查找,再剪切,再粘贴。
回复

使用道具 举报

发表于 2013-7-21 20:45 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub CommandButton1_Click()
  2.     Dim rg As Range
  3.     On Error Resume Next
  4.     If Len(Me.TextBox1) Then
  5.         Set rg = Range("a:a").Find(what:=Me.TextBox1, lookat:=xlWhole)
  6.         If rg Is Nothing Then
  7.             MsgBox "单号 " & Me.TextBox1.Value & " 有误"
  8.             Me.TextBox1.Value = ""
  9.             Me.TextBox1.SetFocus
  10.         Else
  11.             With rg
  12.                 .Resize(, 8).Copy Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1)
  13.                 .EntireRow.Delete
  14.             End With
  15.         End If
  16.     Else
  17.         MsgBox "请输入单号后再进行操作"
  18.         Me.TextBox1.SetFocus
  19.     End If
  20. End Sub
复制代码
回复

使用道具 举报

发表于 2013-7-21 20:49 | 显示全部楼层
  1. Private Sub CommandButton1_Click()
  2.     Dim rg As Range
  3.     Dim arr
  4.     On Error Resume Next
  5.     If Len(Me.TextBox1) Then
  6.         Set rg = Range("a:a").Find(what:=Me.TextBox1, lookat:=xlWhole)
  7.         If rg Is Nothing Then
  8.             MsgBox "单号 " & Me.TextBox1.Value & " 有误"
  9.         Else
  10.             With rg
  11.                 arr = .Resize(, 8).Value
  12.                 .EntireRow.Delete
  13.                 Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, UBound(arr, 2)).Value = arr
  14.             End With
  15.         End If
  16.     Else
  17.         MsgBox "请输入单号后再进行操作"
  18.     End If
  19.     Me.TextBox1.Value = ""
  20.     Me.TextBox1.SetFocus
  21. End Sub
复制代码
回复

使用道具 举报

发表于 2013-7-21 20:59 | 显示全部楼层
。。。。。。。。。。。。。。。。。。。。。

示例.zip

13.9 KB, 下载次数: 3

回复

使用道具 举报

 楼主| 发表于 2013-7-21 22:04 | 显示全部楼层
感谢各位的帮忙
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 04:28 , Processed in 0.864861 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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