Excel 从行上的单元格值添加前缀
我正在创建一个宏循环,它从a列获取值,并将其作为前缀添加到该行D列之后的其余单元格中。当它到达一个空单元格时,它会转到下一行并重复该过程,直到列A单元格为空为止。我在第一行使用了这段代码,但我似乎无法让它循环到其他行Excel 从行上的单元格值添加前缀,excel,vba,loops,prefix,Excel,Vba,Loops,Prefix,我正在创建一个宏循环,它从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)) I
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
你能发布工作代码吗,即使它有错误。此代码不是有效的VBA。你有一个Else但没有If,Sub End而不是End Sub…对不起,这是代码,你的意思是如果A1中有a,D1中有b,E1中有c,那么D1应该结束为ab,E1应该结束为ac?是的。我知道哪里出了问题。你解决问题了吗?