【问题标题】:Adding Prefix from cell value on row从行上的单元格值添加前缀
【发布时间】:2018-08-09 12:21:17
【问题描述】:

我正在创建一个宏循环,该循环从 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      

对正确道路的任何帮助将不胜感激。

【问题讨论】:

  • 请您发布工作代码,即使它出错。此代码不是有效的 VBA。你有一个 Else 但没有 If,"Sub End" 而不是 "End Sub" ...
  • 对不起,这里是代码,
  • 你的意思是如果 A1 中有“a”,D1 中有“b”,E1 中有“c”,那么 D1 应该以“ab”结尾,而 E1 应该以“ac”结尾?
  • 是的,没错。我知道我哪里错了。
  • 那你的问题解决了吗?

标签: excel vba loops prefix


【解决方案1】:

感谢帮助我解决了这个问题

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                                                                                           

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2018-12-05
    • 2022-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多