答案 0 :(得分:3)
这样的事情对你有用:
=--(IF(OR(--LEFT(A1,1)={3,5,7,9}),2,6)&A1)
答案 1 :(得分:2)
Select Case语句可以轻松进行多重比较。
dim rw as long
with worksheets("sheet1")
for rw = 2 to .cells(.rows.count, "A").end(xlup).row
select case int(left(.cells(rw, "A").value2, 1))
case 3, 5, 7, 9
.cells(rw, "A") = int(2 & .cells(rw, "A").value2)
case else
.cells(rw, "A") = int(6 & .cells(rw, "A").value2)
end select
next rw
.range(.cells(2, "A"), .cells(.rows.count, "A").end(xlup)).numberformat = "0 000-0000"
end with
答案 2 :(得分:0)
如果使用公式在新列中重新创建列表,请使用:
=IF(OR(LEFT(A2)="3",LEFT(A2)="5",LEFT(A2)="7",LEFT(A2)="9"),2&A2,6&A2)
答案 3 :(得分:0)
如果要通过VBA执行此操作,请运行以下代码序列:
Sub AddNumber()
Dim i As Long, j As Long
Dim Strt As String
i = 2 'your first row index with data
j = 1 'the column index your list is located (e.g. column A)
Do While Cells(i, j) <> ""
Strt = Left(Cells(i, j), 1)
Select Case Strt
Case 3, 5, 7, 9
Cells(i, j) = 2 & Cells(i, j)
Case Else
Cells(i, j) = 6 & Cells(i, j)
End Select
i = i + 1
Loop
End Sub