excel - 根据比率将数字添加到范围
问题描述
对于背景故事,尝试根据每个小计与总费用的比率将固定费用添加到费用小计 (Y17:Y46)。尝试过,收效甚微。任何帮助,将不胜感激。Flatrefffee 和 Total 之前已在宏中分配了一个值。
Sub Flat_Fee()
'Adds in the flat referral fee, if it's a number
Dim cell As Range
Dim total As Integer
For Each cell In Range("Y17:Y46").Select
If IsNumeric(flatreffee) And cell.Value > 0 Then
cell = cell + (cell / total) * flatreffee
End If
Next cell
End Sub
解决方案
' After first hard-coding total and flatrefee
' and **removing ".Select"** this worked for me.
Sub Flat_Fee()
'Adds in the flat referral fee, if it's a number
Dim cell As Range
Dim total As Integer
For Each cell In Range("Y17:Y46")
If IsNumeric(flatreffee) And cell.Value > 0 Then
cell = cell + (cell / total) * flatreffee
End If
Next cell
End Sub
推荐阅读
- android - 如何在 Android 中等待异步 API?
- mysql - MySQL 几何数据类型的语法错误或访问冲突
- html - 尝试将 3 个图像和 3 个文本与 flexbox 对齐在同一行
- jquery - 与 ember.js 中的模态叠加一起使用时,ag-grid 调整列的大小需要很长时间才能响应
- react-native - DoneButton 未在“react-native-app-intro-slider-rerender-on-prop-change”中呈现
- python - 在 ADLS2 中合并通过 DataBricks 准备的 CSV 文件
- android - 如何使用 JobIntentService 一个接一个地执行多个任务
- react-native - 如何创建从 32 位到 64 位的签名 apk?
- reactjs - ReferenceError:未定义存储
- sql - 选择语句具有新列的多表,其值取决于不同表中的其他列