Home > Mobile >  VBA: For Each loop in a filtered list and ADD text to each cell
VBA: For Each loop in a filtered list and ADD text to each cell

Time:11-09

I managed to modify only the cells in a filtered list using rng.SpecialCells(xlCellTypeVisible), but when i run the code, it takes all the text in all the cells (in the range of the filtered list) and then proceeds to ADD these to each cell. I just want to add a single frase to each cell, not take all the text from all cells and ADD to all the cells. Here is the code:

For Each cl In rng.SpecialCells(xlCellTypeVisible)
    rng.SpecialCells(xlCellTypeVisible).Value = ActiveCell.Value & " - [Text here " & myVariable & "]"
       
    Next cl

Thanks in advance

CodePudding user response:

Try it like this:

For Each cl In rng.SpecialCells(xlCellTypeVisible)
    cl.Value = cl.Value & " - [Text here " & myVariable & "]"
Next cl
  • Related