EXCEL怎么批量替换,不同数据对应不同的值
答案:7 悬赏:70 手机版
解决时间 2021-11-24 12:18
- 提问者网友:雾里闻花香
- 2021-11-24 05:12
EXCEL怎么批量替换,不同数据对应不同的值
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-11-24 05:21
假设第一行为表头,数据从第2行开始。在表2的L2输入公式: =表1!q2,然后将该公式下拉至表格最后一行。
全部回答
- 1楼网友:三千妖杀
- 2021-11-24 10:32
新建 一个对应关系表,然后用VLOOKUP函数
- 2楼网友:长青诗
- 2021-11-24 09:43
录一个查找替换的宏(选项里单元格匹配),赋予一个按钮,每次点一下按钮就OK了。
Sub Macro2()
'
' Macro2 Macro
'
'
Cells.Replace What:="1", Replacement:="玉米", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="2", Replacement:="莲子", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="3", Replacement:="大豆", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
这是我录制的1、2、3,可以向下复制,并修改一下里面的内容。
Sub Macro2()
'
' Macro2 Macro
'
'
Cells.Replace What:="1", Replacement:="玉米", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="2", Replacement:="莲子", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="3", Replacement:="大豆", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
这是我录制的1、2、3,可以向下复制,并修改一下里面的内容。
- 3楼网友:西风乍起
- 2021-11-24 08:19
=INDEX({"玉米";"大豆";"莲子";"红薯";"芋头";"鸡蛋";"黑米";"黄油";"蛋卷";"青菜"},MATCH(A2,{1;2;3;4;9;19;20;35;40;45},0))
下拉
或
=VLOOKUP(A2,{1,"玉米";2,"大豆";3,"莲子";4,"红薯";9,"芋头";19,"鸡蛋";20,"黑米";35,"黄油";40,"蛋卷";45,"青菜"},2,FALSE)
下拉
下拉
或
=VLOOKUP(A2,{1,"玉米";2,"大豆";3,"莲子";4,"红薯";9,"芋头";19,"鸡蛋";20,"黑米";35,"黄油";40,"蛋卷";45,"青菜"},2,FALSE)
下拉
- 4楼网友:西岸风
- 2021-11-24 07:57
利用宏:
Function Dict(i As Integer) As String
s = ""
Select Case i
Case 1: s = "玉米"
Case 2: s = "大豆"
Case 3: s = "莲子"
Case 4: s = "红薯"
Case 9: s = "芋头"
Case 35: s = "黄油"
Case 40: s = "蛋卷"
Case 45: s = "青菜"
Case 20: s = "黑米"
Case 19: s = "鸡蛋"
'case 100: s="..."
Case Else: s = "添加你的词条"
End Select
Dict = s
End Function
Sub ReplaceAll()
'MsgBox Worksheets.Count
Dim ws As Worksheet
Set ws = Worksheets(1)
'MsgBox ws.Cells(1, 2).Value
'MsgBox ws.Range("a1:a5").Cells.Count
i = 1 ' 改成“替换前”的首行号
k = 1 ' 改成“替换前”所在的列号
j = 5 ' 改成“替换后”所在的列号
v = ws.Cells(i, k).Value
Do
ws.Cells(i, j) = Dict(CInt(v))
i = i + 1
v = ws.Cells(i, k)
Loop While v <> 0
End Sub
Function Dict(i As Integer) As String
s = ""
Select Case i
Case 1: s = "玉米"
Case 2: s = "大豆"
Case 3: s = "莲子"
Case 4: s = "红薯"
Case 9: s = "芋头"
Case 35: s = "黄油"
Case 40: s = "蛋卷"
Case 45: s = "青菜"
Case 20: s = "黑米"
Case 19: s = "鸡蛋"
'case 100: s="..."
Case Else: s = "添加你的词条"
End Select
Dict = s
End Function
Sub ReplaceAll()
'MsgBox Worksheets.Count
Dim ws As Worksheet
Set ws = Worksheets(1)
'MsgBox ws.Cells(1, 2).Value
'MsgBox ws.Range("a1:a5").Cells.Count
i = 1 ' 改成“替换前”的首行号
k = 1 ' 改成“替换前”所在的列号
j = 5 ' 改成“替换后”所在的列号
v = ws.Cells(i, k).Value
Do
ws.Cells(i, j) = Dict(CInt(v))
i = i + 1
v = ws.Cells(i, k)
Loop While v <> 0
End Sub
- 5楼网友:独行浪子会拥风
- 2021-11-24 06:32
Function rep(va As range, rf As range, j As Integer, k As Integer)
Dim i As Integer
Dim str As Integer
str = va.Formula
For i = 1 To rf.Rows.Count
str = Replace(str, rf.Cells(i,j), rf.Cells(i,k)+"┋")
Next
rep = Replace(str,"┋","")
End Function
'//批两替换公式
'//rep(va单元格,rf固定区域,j被替换值列序号,k替换值列序号,pre防伪字符)
'//例子:A1100008,A1100009,A1100010替换成 A1100009,A1100010,A1100011是依次这样填充
'判断出设置,轮流用可以替换内容去替换
'i=1 A1100008,A1100009,A1100010
'i=2 A1100009┋,A1100009,A1100010
'i=3 A1100009┋,A1100010┋,A1100010
'i=4 A1100009┋,A1100010┋,A1100011┋
'end A1100009,A1100010,A1100011
Dim i As Integer
Dim str As Integer
str = va.Formula
For i = 1 To rf.Rows.Count
str = Replace(str, rf.Cells(i,j), rf.Cells(i,k)+"┋")
Next
rep = Replace(str,"┋","")
End Function
'//批两替换公式
'//rep(va单元格,rf固定区域,j被替换值列序号,k替换值列序号,pre防伪字符)
'//例子:A1100008,A1100009,A1100010替换成 A1100009,A1100010,A1100011是依次这样填充
'判断出设置,轮流用可以替换内容去替换
'i=1 A1100008,A1100009,A1100010
'i=2 A1100009┋,A1100009,A1100010
'i=3 A1100009┋,A1100010┋,A1100010
'i=4 A1100009┋,A1100010┋,A1100011┋
'end A1100009,A1100010,A1100011
如上公式,可以替换互相覆盖的序号,比如上面的例子
- 6楼网友:蓝房子
- 2021-11-24 05:28
把需要替换的这些做成列表放到sheet2里面,分别在A,B列 A列放数字,B列放中文
假定你的这些数字是在A列,可以在后面空白列的第一行填入公式=vlookup(A1,sheet2!A:B,2,0)
然后下拉,再把这一列复制,选中数字那一列,选择性粘贴——数值
就可以了
数字不是在A列的话,把公式里面那个A1这里改一下,改成实际所在的列就可以了
假定你的这些数字是在A列,可以在后面空白列的第一行填入公式=vlookup(A1,sheet2!A:B,2,0)
然后下拉,再把这一列复制,选中数字那一列,选择性粘贴——数值
就可以了
数字不是在A列的话,把公式里面那个A1这里改一下,改成实际所在的列就可以了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯