加在前面的数字我想在他们面前添加新的号码,根据第一号通过确定第一数量的Excel
- 如果第一个数字是3,5,7,9,然后在前面加2
- 否则前6
添加使用微距按钮 enter image description here
加在前面的数字我想在他们面前添加新的号码,根据第一号通过确定第一数量的Excel
添加使用微距按钮 enter image description here
如果用一个公式来重新创建一个新列的列表,使用这样的:如果你想通过VBA做
=IF(OR(LEFT(A2)="3",LEFT(A2)="5",LEFT(A2)="7",LEFT(A2)="9"),2&A2,6&A2)
我正在使用这个宏函数 –
我刚刚提交了使用VBA的另一个答案。看一看! –
你可以看看我添加的图片,它更难,因为它不是一个collum。 –
像这样的东西应该为你工作:
=--(IF(OR(--LEFT(A1,1)={3,5,7,9}),2,6)&A1)
我真的很新,什么是( - )? –
这就是通常所说的[double unary](http://stackoverflow.com/questions/3286197/what-does-in-excel)。如果您愿意,可以将其解读为“负面”。它的目的是将字符串转换为数字(例如,将字符串“2”转换为数字“2”以执行数字比较) – tigeravatar
@AnGr - 当然,使用谷歌搜索[什么是 - 在Excel中](https ://www.google.ca/webhp?sourceid = chrome-instant&rlz = 1C1CHZL_enCA733CA733&ion = 1&espv = 2&ie = UTF-8#q = what + is + - + in + excel)本来可以告诉你,输入你的问题,更不用说[tigeravatar](http://stackoverflow.com/users/2665425/tigeravatar)回答。 – Jeeped
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
,运行下面的代码序列:
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
我可以使用Pic添加的图片来调整此代码吗? –
re:'*我有一列电话号码*' - 您的图片(最近通过编辑添加)显示5列电话号码。 – Jeeped
我的错可以帮到您吗? –
就在我看到您自己尝试过的代码时。 – Jeeped