Excel VBA selection.replace and, if replaced, put the text in column a from the replaced row

I have a macro like:

Columns("F:M").Select Selection.Replace What:=",", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _ ReplaceFormat:=False 

But I want to put the current date (or even just a line of text) in cell A of the line in which the replacement occurred.

+4
source share
1 answer

I assume that you will need to replace your replacement with searches and replace. Sort of:

 Dim c As Range Columns("F:M").Select Set c = Selection.Find(What:=",", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False) If Not c Is Nothing Then Do c.Replace What:=",", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _ ReplaceFormat:=False Cells(c.Row, 1).Value = Date Set c = Selection.FindNext(c) Loop While Not c Is Nothing End If 
+4
source

Source: https://habr.com/ru/post/1340141/


All Articles