Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
楼主: 兰色幻想

VBA80集第11集练习题答案上交贴

  [复制链接]
发表于 2019-3-9 16:01 | 显示全部楼层
看一下
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

发表于 2019-3-10 11:15 | 显示全部楼层
Sub 替换正数()
Dim rg As Range
Range(Cells(1, 1), Cells(4, 4)).Select
For Each rg In Range(Cells(1, 1), Cells(4, 4))
  If rg.Value > 0 Then
     rg.Value = "正数"
End If
Next
End Sub

Sub 选取正数所在行()
Dim rg As Range
Dim rs As Range
For Each rg In Range("a2,c12")
If rg Like "####" And rg.Value > 0 Then
Set rs = rg
Set rs = Union(rs, rg)
End If
Next
rs.EntireRow.Select
End Sub

老师,如何判断单元格是否为数字?
另外我第二个代码为什么运行一半就不循环了?

回复

使用道具 举报

匿名  发表于 2019-3-10 20:42
回复

使用道具

匿名  发表于 2019-3-10 20:42
萨达所大所大所多
回复

使用道具

发表于 2019-3-11 21:03 | 显示全部楼层
做完了,但是不对
回复

使用道具 举报

发表于 2019-3-12 15:31 | 显示全部楼层
想了解一下正确答案
回复

使用道具 举报

发表于 2019-3-13 16:12 | 显示全部楼层
正确答案?
回复

使用道具 举报

匿名  发表于 2019-3-13 22:03
fuxingcaipiao 发表于 2019-3-10 11:15
Sub 替换正数()
Dim rg As Range
Range(Cells(1, 1), Cells(4, 4)).Select

Sub 选中内容数字替换成正数方法1()
Dim r As Integer, R1 As Integer
Dim c As Integer, C1 As Integer
R1 = Selection.Rows.Count
C1 = Selection.Columns.Count
For r = 0 To R1 Step 1
    For c = 0 To C1 Step 1
      If Application.IsNumber(Selection.Range("A1").Offset(r, c)) And Selection.Range("A1").Offset(r, c) > 0 Then
         Selection.Range("A1").Offset(r, c) = "正数"
      End If
    Next c
Next r
End Sub

Sub 选中正数行()
Dim rg As Range, Un As Range
Set Un = Range("A2")
For Each rg In Range("A2:C12")
   If Application.IsNumber(rg) And rg.Value > 0 Then
      Set Un = Union(Un, rg)
    End If
Next rg
Un.EntireRow.Select
End Sub

Sub 选中内容数字替换正数方法2()
Dim rg As Range
For Each rg In Selection
  If Application.IsNumber(rg) And rg.Value > 0 Then
     rg.Value = "正数"
  End If
Next rg
End Sub


回复

使用道具

匿名  发表于 2019-3-13 22:04
fuxingcaipiao 发表于 2019-3-10 11:15
Sub 替换正数()
Dim rg As Range
Range(Cells(1, 1), Cells(4, 4)).Select

判断是否为数字可以使用 application.isNumber()这个系统提供的方法
回复

使用道具

匿名  发表于 2019-3-13 22:11
看下
回复

使用道具

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

本版积分规则

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

GMT+8, 2024-5-20 02:35 , Processed in 0.280745 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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