請幫助一個新手。 使用 Excel VBA,我試圖用連字符來格式化 A 列中的文本,但只有在 B 列包含字母 B 的情況下。
我找到了以下代碼,其中一個是用連字符格式化A列中的單元格,另一個是檢查B列是否有正確的值,但似乎無法將它們結合起來使用。請幫助我。 謝謝。
Sub AddDashes()
Dim Cell As Range
On Error GoTo NoFilledCells
For Each Cell In Range("A1:A" & Cells(Rows. Count, "A").End(xlUp).Row) .SpecialCells(xlCellTypeConstants)
Cell.Value = Format(Replace(Cell.Value, "-", ""), "@@@@@-@@-@@@@")
下一步)
NoFilledCells:。
End Sub
和
Sub ChangeColumn()
Dim LastRow As Long
Dim I As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Range("B"/span> & i).Value = "B"/span> Then
Range("A" & i).Value = "格式化文本,連字符如上"。
End If
Next i
End Sub
uj5u.com熱心網友回復:
Option Explicit
Sub AddDashes()
Dim ws As 作業表, cell As Range
Dim LastRow As Long 最后一行
Set ws = ActiveSheet
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
For Each cell In ws.Range("A2:A"/span> & LastRow)
If cell. Offset(0, 1) = "B" Then ' col B
cell.Value = Format(Replace(cell.Value, "-", ""), "@@@@@-@@- @@@@")
結束 如果
下一步 下一步
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/314526.html
標籤:
