专栏名称: 完美Excel
Excel与VBA技术学习与实践
今天看啥  ›  专栏  ›  完美Excel

搜索并汇总多个工作表中的数据

完美Excel  · 公众号  · Excel  · 2024-07-03 05:13

文章预览

学习Excel技术,关注微信公众号: excelperfect 标签: VBA 下面的示例搜索工作簿中除工作表“汇总表”外的多个工作表中的数据,将满足条件的数据所在行复制到指定工作表。 Sub SearchAndCombineSheets() Dim FirstAddress As String Dim WhatFor As String Dim c As Range Dim ws As Worksheet  WhatFor  =  InputBox("搜索什么数据?", "搜索条件") If WhatFor = Empty Then Exit Sub For Each ws In Worksheets    If ws.Name  < > "汇总表" Then With ws.Columns(7)        Set c  =  .Find(WhatFor, LookIn:=xlValues, LookAt:=xlPart) If Not c Is Nothing Then FirstAddress = c.Address Do            If c.EntireRow.Cells(1, 6).Value > 0 Then              c.EntireRow.Copy Destination : =Worksheets("汇总表").Range("A" &  Rows.Count).End(xlUp).Offset(1, 0)   End If Set c = .FindNext(c)        ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照
总结与预览地址:访问总结与预览