|
题目1:
任意选取本工作表中的一个区域,然后把选取区域中的大于0的数字替换为字符“正数”
- Sub test()
- Dim rng As Range
- For Each rng In Selection
- If rng.Value > 0 And IsNumeric(rng.Value) Then
- rng.Value = "正数"
- End If
- Next
- End Sub
复制代码
题目2:
用代码一次选取“A2:C12”区域所有大于0数字所在的行
- Sub test2()
- Dim iColum As Integer
- Dim iRow As Integer
- Dim rng As Range
- For iColum = 1 To 3 Step 1
- For iRow = 2 To 12 Step 1
- If Cells(iRow, iColum) > 0 And IsNumeric(Cells(iRow, iColum)) = True Then
- If rng Is Nothing Then
- Set rng = Cells(iRow, iColum)
- Else
- Set rng = Union(rng, Cells(iRow, iColum))
- End If
- End If
- Next iRow
- Next iColum
- rng.EntireRow.Select
- End Sub
复制代码 |
|