循环在vba中,将通过所有的表并获取数据 [英] Loop in vba which will go through all sheets and get data

查看:120
本文介绍了循环在vba中,将通过所有的表并获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看有没有人能够在VBA Excel中显示一个循环,它将执行以下操作:



假设我有一个variouse未知数名单不明,而不是最后一张作为结果表的表格,我希望这个周期去除除最后一张之外的所有其他表格,并从他们那里获取字段名称为公司名称并排序的字段所有这些名称都是从最后一个结果表中的第一个起开始的名称,而最后一张表的名称将始终是相同的结果表,因此如果需要,名称可能被用作异常。



Thaks。

解决方案

现在我没有Excel来测试,而且你要求我为你而努力。我会给你一个小块,应该以正确的方式。



将每张纸上的A1复制到工作表结果表中。

  Dim Sh1 As WorkSheet,Sh2 As WorkSheet,R As Integer 
Set Sh1 = Sheets(Result sheet)
R = 1
对于每个Sh2在WorkSheets
如果Sh2.Name<> 结果表然后
Sh1.Cells(R,1)= Sh2.Cells(1,1)
R = R + 1
End If
Next Sh2

最后你会得到Sh1中的数据,你可以使用Sh2.Sort()来排序这是你想要的。


I would like to see if somebody can show me a cycle in VBA Excel that will do the following action:

Let's say that I have a variouse unknown number of sheets with unknown names and than one final sheed as a "result sheet" I would like this cycle to go trought all other sheets except the last one and to grab from them the Field which have a field name: "Company Name" and to sort all that names one after another starting from the first one in the last "Result sheet"

and the name of the last sheet will be always te same Result Sheet, so that name might be used as an exception in case if it is needed.

Thaks.

解决方案

Right now I don't have Excel to test, and you are asking me to make it for you without even trying. I will give you a little piece that should put you in the right way.

This copies A1 from each sheet into the sheet Result sheet.

Dim Sh1 As WorkSheet, Sh2 As WorkSheet, R As Integer
Set Sh1 = Sheets("Result sheet")
R = 1
For Each Sh2 In WorkSheets
  If Sh2.Name <> "Result sheet" Then
    Sh1.Cells(R, 1) = Sh2.Cells(1, 1)
    R = R + 1
  End If
Next Sh2

At the end you end up with the data in Sh1, and you can play with Sh2.Sort() to sort it the way you want.

这篇关于循环在vba中,将通过所有的表并获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆