|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 满坛皆为吾师 于 2024-5-27 15:31 编辑
打工留藏一手基操啊
- ' 定义一个函数exw,接受6个参数
- Private Function exw(podexw As String, p_volume As Single, p_charge As Single, Origin As String, Load As String, Disc As String) As Single
- Dim r As Integer
- ' 定义变量vl为单精度浮点数,用于存放计算后的体积或费用比值
- Dim vl As Single
-
- ' 判断条件:如果每300单位费用所对应的体积大于给定的体积,则vl等于该比值;否则,vl等于给定的体积。
- If p_charge / 300 > p_volume Then
- vl = p_charge / 300
- Else
- vl = p_volume
- End If
-
- ' 使用For循环从第23行遍历到第145行
- For r = 23 To 145
- ' 在循环内检查当前行是否满足特定条件:
- ' 第一列(Cells(r, 1))的值等于Origin,
- ' 第三列(Cells(r, 3))的值等于Load,
- ' 第四列(Cells(r, 4))的值等于Disc,
- ' 且传入的podexw参数等于"EXW"
- If Sheet1.Cells(r, 1).Value = Origin And Sheet1.Cells(r, 3).Value = Load And Sheet1.Cells(r, 4).Value = Disc And podexw = "EXW" Then
- ' 如果条件满足,将第11列(Cells(r, 11))的值赋给函数返回值exw,并结束循环
- exw = Sheet1.Cells(r, 11).Value
- Exit For
- End If
- Next r
- End Function
复制代码
|
|