excel - 从行上的单元格值添加前缀
问题描述
我正在创建一个宏循环,该循环从 A 列获取值并将其作为前缀添加到该行 D 列之后的其余单元格。当它到达一个空单元格时,它会转到下一行并重复该过程,直到 A 列单元格为空。我已经使用了适用于第一行的代码,但我似乎无法让它循环到其他行。
Sub FLOC
Dim I as Integer
Dim j as Integer
I=4
j=1
'Check that Column A is not empty to stop the Loop
While Not IsEmpty(Cells(j, 1))
If Not IsEmpty(Cells(j,i)) Then
'Select Column D in that row
Cells(j, i).Select
'Add the prefix from Column A to the rest of the Cells on the row
ActiveCell.Value = Cells(1, j).Value & ActiveCell.Value
i = i + 1
'When a empty cell is reached move the ActiveCell to next row, Column D.
Else
i = 4
j = j + 1
Endif
Wend
Sub End
对正确道路的任何帮助将不胜感激。
解决方案
感谢您帮助我解决了这个问题
Sub FLO2 ()
Dim i As Double
Dim j As Double
Dim FLOC As String
j = 1
i = 4
FLOC = Cells(j, 1)
While Not IsEmpty(FLOC)
If Not IsEmpty(Cells(j, i)) Then
Cells(j, i).Select
ActiveCell.Value = Cells(j, 1).Value & ActiveCell.Value
i = i + 1
Else
i = 4
j = j + 1
End If
Wend
Sub End
推荐阅读
- javascript - 导出到全局范围的函数未定义(webpack + babel)
- django - python3 manage.py makemigrations 未检测到更改
- vb.net - Webbrowser1.ShowPrintDialog() 未在 Windows 7 上显示,但在 Windows 10 中显示
- for-loop - 如何调整程序以关闭循环并打印预期结果?
- c++ - 未指定 lambda 函数的返回类型时的段错误
- .net-core - 不知道如何注入 LinkGenerator
- tableau-api - 托管在云平台中的 Tableau Web 数据连接器陷入无限循环
- ios - 如何在 Swift 中对日期组件进行排序?
- javascript - Chrome 扩展程序:通过语音识别呼叫访问麦克风
- prometheus - Promotheus - 查询以增加事件百分比