英文:
find values in sheet then replace different values for each column
问题
如何在工作表中查找一个值,然后替换每一列的不同值?
我无法想出一种获取非连续单元格范围的值以进行循环的方法。
附上之前和之后的图片链接:
英文:
how do you find a value in a sheet then replace with different values for each columns
i cant think of a way get the range of non contigous cells with the values to loop thru it
attached before and after below:
答案1
得分: 1
替换字符为列索引
Sub ReplaceChar()
Const Char As String = "a"
Dim ws As Worksheet: Set ws = ActiveSheet ' 改进!
Dim rg As Range: Set rg = ws.UsedRange
Dim crg As Range, c As Long
For Each crg In rg.Columns
c = c + 1
crg.Replace Char, c, xlWhole, , False
Next crg
MsgBox "字符已替换。", vbInformation
End Sub
英文:
Replace Character With Column Index
Sub ReplaceChar()
Const Char As String = "a"
Dim ws As Worksheet: Set ws = ActiveSheet ' improve!
Dim rg As Range: Set rg = ws.UsedRange
Dim crg As Range, c As Long
For Each crg In rg.Columns
c = c + 1
crg.Replace Char, c, xlWhole, , False
Next crg
MsgBox "Character replaced.", vbInformation
End Sub
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论