Private Sub CommandButton1_Click()
PrivateSubCommandButton1_Click()DimaAsRange,bAsRangear=[B65536].End(3).RowFori=3ToarI...
Private Sub CommandButton1_Click()
Dim a As Range, b As Range
ar = [B65536].End(3).Row
For i = 3 To ar
If Cells(i, 16) = "已经更换" Or Cells(i, 16) = "五周之外过来更换" Then
If a Is Nothing Then
Set a = Rows(i)
Else
Set a = Union(a, Rows(i))
End If
ElseIf Cells(i, 16) = "取消预留" Then
If b Is Nothing Then
Set b = Rows(i)
Else
Set b = Union(b, Rows(i))
End If
End If
Next
If Not a Is Nothing Then
a.Copy Sheets("已经更换").Range("B65536").End(3).Offset(1, -1)
a.Delete
End If
If Not b Is Nothing Then
b.Copy Sheets("取消预留").Range("B65536").End(3).Offset(1, -1)
b.Delete
End If
End Sub
正在学习编程,请高手帮忙解读,谢谢 展开
Dim a As Range, b As Range
ar = [B65536].End(3).Row
For i = 3 To ar
If Cells(i, 16) = "已经更换" Or Cells(i, 16) = "五周之外过来更换" Then
If a Is Nothing Then
Set a = Rows(i)
Else
Set a = Union(a, Rows(i))
End If
ElseIf Cells(i, 16) = "取消预留" Then
If b Is Nothing Then
Set b = Rows(i)
Else
Set b = Union(b, Rows(i))
End If
End If
Next
If Not a Is Nothing Then
a.Copy Sheets("已经更换").Range("B65536").End(3).Offset(1, -1)
a.Delete
End If
If Not b Is Nothing Then
b.Copy Sheets("取消预留").Range("B65536").End(3).Offset(1, -1)
b.Delete
End If
End Sub
正在学习编程,请高手帮忙解读,谢谢 展开
1个回答
展开全部
’按钮点击事件
Private Sub CommandButton1_Click()
Dim a As Range, b As Range’单元格对象变量
ar = [B65536].End(3).Row’行的极限为65536,
’[b65536] 单元格B65536的一种表示方法
‘END(3) 也可以写成 End(xlUp) 向上查找最后一个非空单元格
’Row 行号
For i = 3 To ar
'遍历每16列,从第3行开始到ar行
If Cells(i, 16) = "已经更换" Or Cells(i, 16) = "五周之外过来更换" Then
’对单元格内容进行判断
If a Is Nothing Then
‘记忆此单元格的内容a
Set a = Rows(i)
Else
Set a = Union(a, Rows(i))'合并区域
End If
ElseIf Cells(i, 16) = "取消预留" Then
If b Is Nothing Then
’记忆内容b
Set b = Rows(i)
Else
Set b = Union(b, Rows(i))
End If
End If
Next
If Not a Is Nothing Then
a.Copy Sheets("已经更换").Range("B65536").End(3).Offset(1, -1)'复制单元格,有偏移量
a.Delete
End If
If Not b Is Nothing Then
b.Copy Sheets("取消预留").Range("B65536").End(3).Offset(1, -1)'同上
b.Delete
End If
End Sub
如果不理解,我可以再补充。
Private Sub CommandButton1_Click()
Dim a As Range, b As Range’单元格对象变量
ar = [B65536].End(3).Row’行的极限为65536,
’[b65536] 单元格B65536的一种表示方法
‘END(3) 也可以写成 End(xlUp) 向上查找最后一个非空单元格
’Row 行号
For i = 3 To ar
'遍历每16列,从第3行开始到ar行
If Cells(i, 16) = "已经更换" Or Cells(i, 16) = "五周之外过来更换" Then
’对单元格内容进行判断
If a Is Nothing Then
‘记忆此单元格的内容a
Set a = Rows(i)
Else
Set a = Union(a, Rows(i))'合并区域
End If
ElseIf Cells(i, 16) = "取消预留" Then
If b Is Nothing Then
’记忆内容b
Set b = Rows(i)
Else
Set b = Union(b, Rows(i))
End If
End If
Next
If Not a Is Nothing Then
a.Copy Sheets("已经更换").Range("B65536").End(3).Offset(1, -1)'复制单元格,有偏移量
a.Delete
End If
If Not b Is Nothing Then
b.Copy Sheets("取消预留").Range("B65536").End(3).Offset(1, -1)'同上
b.Delete
End If
End Sub
如果不理解,我可以再补充。
追问
我的基础太弱了,大侠能推荐点入门的文章或视频吗?
追答
Visual Basic 从入门到精通视频教程-VB视频教程下载-eNet网络学院http://www.enet.com.cn/eschool/video/vb/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询