excel - For loop in excel vba not showing values to cell
问题描述
I'm trying to use "for loop" to get some specific values, code runs perfect but values do not print to destination. subcode, where the problem is, looks like this :
lastRow = Range("H" & Rows.Count).End(xlUp).Row
For i = 5 To lastRow
radius = Range("C" & i).Value
spacing = Range("L" & i).Value
Select Case radius
Case 0 To 450
spacing = 6
Case 451 To 750
spacing = 9
Case 751 To 2000
spacing = 18
End Select
Next i
解决方案
In your code you are storing a value from Range("L" & i).Value
to the variable spacing
. Then, in your For
loop you are assigning a new value to the variable, but you are not setting the range (cell) to that value.
The below, albeit shoddy, will work for you.
lastRow = Range("H" & Rows.Count).End(xlUp).Row
For i = 5 To lastRow
radius = Range("C" & i).Value
Select Case radius
Case 0 To 450
Range("L" & i).Value = 6
Case 451 To 750
Range("L" & i).Value = 9
Case 751 To 2000
Range("L" & i).Value = 18
End Select
Next i
推荐阅读
- vue.js - 在 Vue.js 中从父组件向动态组件传递数据
- mysql - 尝试使用 mysql 秘密引擎插件设置安装在 GCP 上的 Vault 时出错
- intellij-idea - IntelliJ .idea 文件夹是本地更改的一部分,尽管它是在 .gitignore 中定义的
- http-headers - FastCGI+lighttpd+C++:如何访问代码中的 HTTP 标头?
- mysql - MySQL CURSOR 循环在过程中添加了一个额外的循环
- bash - 如何在 bash 脚本中的 source env shell 之后运行命令
- javascript - JsFiddle:库“加载类型”是指库还是我的代码?
- php - 学说:从数据库中生成实体
- c# - 如何在 C# 中模拟文件上传?
- javascript - 在javascript中将函数作为动态函数调用为数组值