vba 查找第一个单元格A1 在本表位置中查找其他excel的和A1相似的单元格,并且定位

Sub XO()

Dim strPath As String
strPath = ThisWorkbook.Path
Call getExcelFile0(strPath)
End Sub


Sub getExcelFile0(sFolderPath As String)
On Error Resume Next
Dim f As String
Dim file() As String
x = 2
wj = 2
k = 2
 ReDim file(1)
file(1) = sFolderPath & "\"

lj = sFolderPath
'Stop
    f = Dir(file(1) & "*.xlsx")     '通配符*.*表示所有文件,*.xlsx Excel文件
    Do Until f = ""
      Cells(2, x).Hyperlinks.Add Anchor:=Cells(2, x), Address:=file(i) & f, TextToDisplay:=f

  Temp = lj & "\" & f   '外部文件路径

       Dim wb As Workbook
       Set wb = GetObject(Temp)
      For Each sh In wb.Worksheets    '数组

       sh.Select
      sheetname = sh.Name
       Cells(3, wj).Value = f
       Cells(4, k).Value = sheetname
    
       findx = "*" & Cells(1, 1) & "*"
      
       With sh.Range("a1:z500")
        '使用通配符查找
        h = 5
        Set c = .Find(findx, LookIn:=xlValues)
        If Not c Is Nothing Then
            FirstAddress = c.Address
            '在这里写根据第一个找到的单元格进行的操作
            Do
           
                '在这里写对根据后续找到的单元格进行的操作
               ' Debug.Print c.Row, c.Column
               ' c.Font.Color = vbRed
                Set c = .FindNext(c)
                r = c.Row  '返回行
                cl = c.Column '返回列
                x1 = c.Address
                 Cells(h, wj) = x1
                 
                h = h + 1
                 
                  Cells(h, wj) = c.Value
                 h = h + 1
                Loop While Not c Is Nothing And c.Address <> FirstAddress
        End If
    End With
   ' wb.Close savechanges:=False
       
       wj = wj + 1
       k = k + 1
       
       Next
      
        x = x + 1
        f = Dir
    Loop
  
End Sub

 


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT技术与企业应用结合的爱好者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值