excel - 选择案例结构
问题描述
我的问题如下,以下“选择案例”,范围在 A1:A100 之间。在我尝试以下代码后,我只获得了我需要的 100 个进度结果的一个结果。代码如下:
Private Sub CommandButton1_Click()
Dim score As Integer, result As String
score = Range("A1").Value
Select Case score
Case Is >= 80
result = "very good"
Case Is >= 70
result = "good"
Case Is >= 60
result = "sufficient"
Case Else
result = "insufficient"
End Select
Range("B1").Value = result
End Sub
解决方案
如果您指定要对已定义范围内的每个单元格执行相同的功能,则可以执行FOR EACH
如下循环:
Private Sub CommandButton1_Click()
Dim score As range, result As String
set score = Range("A1:a100")
for each c in score.cells
Select Case c.value
Case Is >= 80
result = "very good"
Case Is >= 70
result = "good"
Case Is >= 60
result = "sufficient"
Case Else
result = "insufficient"
End Select
c.offset(0,1) = result 'specifies the cell 1 column to the right of the current cell
next c
End Sub
推荐阅读
- angular - 在 ngOnDestroy 中调用的 destroy() 抛出无法读取未定义的属性“forExport”
- c# - 使用显式运算符转换实现相同接口的两个类时出现运行时错误
- java - 检索值时应用程序不断崩溃
- apache-kafka - Druid 仅解析从单个 kafka 消息消耗的 json 对象列表的第一个 json 对象
- php - 如何在 Laravel 中处理外部事件?
- spring-boot - 如何对自定义 mongo 存储库进行集成测试?
- sql-server - 查找一列的两行属于另一列的同一行
- pandas - Pandas 数据帧到 2D numpy 数组
- mongodb - 创建将匹配 MongoDB 中的查询的复合索引
- c++ - 用锯齿线连接两条线