最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

自用代碼實(shí)現(xiàn)Xlookup

2023-03-27 21:48 作者:你的布林  | 我要投稿

Sub UpdateDataInFolder()

? ? Dim folderPath As String, filePath As String

? ? Dim sozSheet As Worksheet, currentSheet As Worksheet

? ? Dim sozRange As Range, currentRange As Range

? ? Dim sozCell As Range, currentCell As Range

? ??

? ? Set sozSheet = ThisWorkbook.Sheets("Soz") '獲取Soz表

? ? Set sozRange = sozSheet.Range("A1").CurrentRegion.Offset(1) '獲取Soz表數(shù)據(jù)區(qū)域(排除表頭)

? ??

? ? folderPath = "C:\Users\username\Desktop\test" '需要替換為你實(shí)際的文件夾路徑

? ? filePath = Dir(folderPath & "\*.xlsx") '查找文件夾內(nèi)的所有xlsx文件

? ??

? ? Application.ScreenUpdating = False '關(guān)閉屏幕更新,加快執(zhí)行速度

? ??

? ? Do Until filePath = ""

? ? ? ? Set currentSheet = Workbooks.Open(folderPath & "\" & filePath).Sheets(1) '打開文件,并獲取第一個(gè)Sheet

? ? ? ? Set currentRange = currentSheet.Range("B1").CurrentRegion.Offset(1) '獲取當(dāng)前Sheet的數(shù)據(jù)區(qū)域(排除表頭)

? ? ? ??

? ? ? ? For Each sozCell In sozRange.Cells '遍歷Soz表的A列單元格

? ? ? ? ? ? Set currentCell = currentRange.Find(what:=sozCell.Value, LookIn:=xlValues, lookat:=xlWhole) '在當(dāng)前Sheet的B列中查找Soz表的A列內(nèi)容

? ? ? ? ? ? If Not currentCell Is Nothing Then '如果找到了相應(yīng)的內(nèi)容

? ? ? ? ? ? ? ? currentCell.Offset(0, 2).Value = sozCell.Offset(0, 1).Value '將對(duì)應(yīng)的D列=Soz表的B列

? ? ? ? ? ? End If

? ? ? ? Next sozCell

? ? ? ??

? ? ? ? currentSheet.Save '保存當(dāng)前表格

? ? ? ? currentSheet.Close '關(guān)閉當(dāng)前表格,釋放內(nèi)存

? ? ? ? filePath = Dir() '查找下一個(gè)文件

? ? Loop

? ??

? ? Application.ScreenUpdating = True '打開屏幕更新

End Sub

上述代碼具體操作為:先獲取Soz表的A列內(nèi)容和對(duì)應(yīng)的D列的值,然后遍歷指定文件夾內(nèi)的所有xlsx文件,在每個(gè)文件中查找對(duì)應(yīng)的值并修改相應(yīng)的D列。最后保存修改并關(guān)閉文件。請(qǐng)根據(jù)實(shí)際需要修改代碼中的文件夾路徑、Soz表的名稱和數(shù)據(jù)區(qū)域的范圍。

自用代碼實(shí)現(xiàn)Xlookup的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
永修县| 吉木乃县| 格尔木市| 札达县| 兴城市| 灌云县| 瑞昌市| 东辽县| 安泽县| 裕民县| 锦州市| 秀山| 大名县| 台北市| 喀喇沁旗| 乐都县| 五家渠市| 山西省| 稻城县| 长沙市| 雅江县| 三门县| 霍城县| 镇沅| 顺平县| 大姚县| 瑞金市| 丰宁| 若羌县| 岗巴县| 崇明县| 南充市| 朝阳市| 嘉鱼县| 章丘市| 瓮安县| 望都县| 吉木乃县| 三都| 武胜县| 青川县|