VBA实现两Excel文件文本匹配、内容替换及批量结构行生成需求
VBA文本匹配与替换需求及现有代码问题
核心需求
- 文本前缀替换:从Workbook A的绿色单元格提取
-后的后半段文本(如EGTR-X-XX-001 - Planta do traçado中的Planta do traçado),在Workbook B的黄色单元格匹配该文本;匹配成功后,用Workbook B的C列蓝色单元格内容(如EGTR-O-P29-001)替换原单元格的前缀部分,结果写回原位置。 - 结构条目更新与新增:
- Workbook A包含Towers、Poles等结构类型,每个结构对应设计、荷载、基础设计及记录项,C列为专属编码;Workbook B是含
Structure 1等项的静态列表。 - 将Workbook A中
EGTR-X-XX-050 - Structure 1替换为EGTR-O-P29-050 - YS1-PR Pole Silhouette,保留下方对应塔/杆的备注内容。 - 新增行:将Workbook A的C列编码与对应结构名称(如
Pole Loading AP1-PR)拼接为新条目,同时复制该结构对应的备注列表。
- Workbook A包含Towers、Poles等结构类型,每个结构对应设计、荷载、基础设计及记录项,C列为专属编码;Workbook B是含
现有Vlookup代码
Sub searchpl() Dim rw As Long, x As Range Dim extwbk As Workbook, twb As Workbook Dim myFile As Variant '选择要打开的Workbook B myFile = Application.GetOpenFilename("Excel Files (*.xl*),*.xl*", , "Choose File", "Open", False) If myFile = False Then Else Set twb = ThisWorkbook Set extwbk = Workbooks.Open(myFile) Set x = extwbk.Worksheets("B").Range("A1:C175") End If With twb.Sheets("A") For rw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row .Cells(rw, 2) = Application.VLookup(.Cells(rw, 1).Value2, x, 2, False) Next rw End With extwbk.Close savechanges:=False End Sub
内容的提问来源于stack exchange,提问作者Frederico Montzel
相关产品推荐
相关产品推荐

