excel - 合并多个单元格的文本
问题描述
如何组合多个单元格的文本,例如将此 excel 公式转换为 VBA 代码单元格F3
应该=Q3&"_"&A3&"_"&D3&"_"&(ROUND(M3/1000,1))&"k"
但我希望它每时每刻都在重复F99= Q99&"_"&A99&"_"&D99&"_"&(ROUND(M99/1000,1))&"k"
使用 VBA 代码:
For Each Cel In Range("A1:A100")
If Cel.Value <> "" Then Cel.Offset(0, 5).Value = *Excel Formula NEED* "Q3&"_"&A3&"_"&D3&"_"&(ROUND(M3/1000,1))&"k""*
说如果 A 列中的值在同一行 E 列中插入文本
解决方案
我还认为一个公式(在空单元格的情况下稍作调整以返回“”)将是最好的。但是,即使您没有回答我的问题并且您想要 VBA 中的解决方案,请测试下一个代码:
Sub testConcatenate()
Dim sh As Worksheet, cel As Range, lastRow As Long
Set sh = ActiveSheet 'please use your sheet here
lastRow = sh.Range("A" & Rows.count).End(xlUp).Row
For Each cel In Range("A1:A" & lastRow)
If cel.value <> "" Then
cel.Offset(0, 5).value = Range("Q" & cel.Row).value & "_" & cel.value & "_" & _
Range("D" & cel.Row).value & "_" & Round(Range("M" & cel.Row).value / 1000, 1) & "k"
End If
Next
End Sub
您可能会在这里澄清""
公式中的含义,“k”的含义以及最后一个字符“*”的用途。我没有用它...
推荐阅读
- angular - 使用 RxJS 无限计算并发的 HttpClient 请求
- android - 在发布构建期间“意外尝试获取没有寄存器的值的寄存器”但未调试
- android - ANDROID SQLITE 数据库错误:无效表
- python - 以降序创建具有词频百分比的字典
- r - 在嵌套 tibble 的两列上应用 purrr::map2
- c# - 重写抽象方法时如何处理不同的返回类型
- react-native-maps - react-native-maps-super-cluster : 如何制作多种类型的集群
- sql - oracle如何将字符串分割为多个特殊字符
- flutter - Flutter - 如何查看 TextFormField 上的前缀,即使没有按下
- angular - 如何在 angular8 路由器事件中将函数与组件绑定?