当前位置: 首页 > news >正文

真空设备 东莞网站建设seo资源网站排名

真空设备 东莞网站建设,seo资源网站排名,邯郸做移动网站价格,注册公司网站怎么做本文介绍如何利用 VBA 的数组(Array) 来提高 Excel 单元格和外部数据传输的性能。如果数量比较大,通过 Array 来传输数据比直接操作单元格要快若干倍。 将 Range 的数据写入 VBA Array 将 Range 数据写入 VBA 的数组非常简单。下面的例子演示了用法&am…

本文介绍如何利用 VBA 的数组(Array) 来提高 Excel 单元格和外部数据传输的性能。如果数量比较大,通过 Array 来传输数据比直接操作单元格要快若干倍。

将 Range 的数据写入 VBA Array

将 Range 数据写入 VBA 的数组非常简单。下面的例子演示了用法:

Dim Arr() as Varint  ' Declare an unallocated array
Arr = Range("A1:C5") ' Arr is now an allocated array

当我们将数据从工作表的range 写入到 VBA 数组的时候,这个数组始终是二维的。第一个维度是行,第二个维度是列。所以,刚才定义的数组有 5 行,有 3 列,等同于 Arr(1 to 5, 1 to 3) 。需要注意的是,即使在 Excel 中只有一行或者一列,这个数组也是二维的,可以理解为 Arr(1 to 1, 1 to 1)。 另外,数组的下标 (LBound) 始终从 1 开始。比如:

Dim Arr() as Variant
Arr = Range("A1:A10")

Arr 相当于 Arr(1 to 10, 1 to 1)

下面的代码演示了如何遍历工作表中 Range 的值:

Public Sub PrintCells()Dim arr() As Variantarr = Range("A1:C5")Dim r As Long  ' r: rowDim c As Long  ' c: columnFor r = 1 To UBound(arr, 1)     '第一个维度是行数For c = 1 To UBound(arr, 2) '第二个维度是列数Debug.Print arr(r, c),NextDebug.PrintNext
End Sub

有一个特例。如果单元格的数量只有一个,那么就不能作为二维数组。上面的代码在一个单元格的时候会出错,需要调整为下面的代码:

Public Sub PrintCells(rng as Range)Dim arr() As VariantIf rng.Cells.Count = 1 ThenReDim arr(1 To 1, 1 To 1)arr(1, 1) = rng.ValueElsearr = rngEnd IfDim r As Long  ' r: rowDim c As Long  ' c: columnFor r = 1 To UBound(arr, 1)     '第一个维度是行数For c = 1 To UBound(arr, 2) '第二个维度是列数Debug.Print arr(r, c),NextDebug.PrintNext
End Sub

将一维数组写入单元格

一维数组可以按行输出,实现的要点:定义一个 Range,将 Range 的列扩充为数组的UBound。

Public Sub WriteOneDimensionArr()Dim arr() As VariantReDim arr(1 To 5)arr(1) = 1arr(2) = 2arr(3) = 3arr(4) = 4arr(5) = 5Dim destination As RangeSet destination = Range("A10")Set destination = destination.Resize(1, UBound(arr)) '对数组进行行扩充destination.Value = arr
End Sub

当然,一维数组也可以实现按列输出:

Public Sub WriteOneDimensionArr2()Dim arr() As VariantReDim arr(1 To 5)arr(1) = 1arr(2) = 2arr(3) = 3arr(4) = 4arr(5) = 5Dim destination As RangeSet destination = Range("A10")Set destination = destination.Resize(UBound(arr), 1) '对数组进行行扩充destination.Value = Application.Transpose(arr)
End Sub

二维数组写入单元格

实际上,将二维数组写入到单元格更加直观。数组的第 1 个维度是行数,第 2 个维度是列数。我们通过下面的示例,演示如果将 A1:C5 的数据拷贝到另外一个区域:

Public Sub CopyCells()Dim arr() As Variantarr = Range("A1:C5")Dim destination As RangeSet destination = Range("A10")destination.Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
End Sub

文章转载自:
http://dinncomagnus.bpmz.cn
http://dinncoagrologist.bpmz.cn
http://dinncomattin.bpmz.cn
http://dinncoswanee.bpmz.cn
http://dinncocradle.bpmz.cn
http://dinncopenlight.bpmz.cn
http://dinncometrication.bpmz.cn
http://dinncoparasiticide.bpmz.cn
http://dinncofrostwork.bpmz.cn
http://dinncobitterroot.bpmz.cn
http://dinncojargonaut.bpmz.cn
http://dinncoenkindle.bpmz.cn
http://dinncoantiterrorism.bpmz.cn
http://dinncotackle.bpmz.cn
http://dinncoarden.bpmz.cn
http://dinncochara.bpmz.cn
http://dinncoberyl.bpmz.cn
http://dinncoadb.bpmz.cn
http://dinncofreebsd.bpmz.cn
http://dinncoparashoot.bpmz.cn
http://dinncompp.bpmz.cn
http://dinncoaptness.bpmz.cn
http://dinncostamineal.bpmz.cn
http://dinncoringbone.bpmz.cn
http://dinncorebounder.bpmz.cn
http://dinncocalutron.bpmz.cn
http://dinncoaeroallergen.bpmz.cn
http://dinncoarrenotokous.bpmz.cn
http://dinncoswagger.bpmz.cn
http://dinncoaposteriori.bpmz.cn
http://dinncoanik.bpmz.cn
http://dinncopsychogenesis.bpmz.cn
http://dinncoarsenous.bpmz.cn
http://dinncoengender.bpmz.cn
http://dinncovelutinous.bpmz.cn
http://dinncoobstinacy.bpmz.cn
http://dinncosprightly.bpmz.cn
http://dinncocalced.bpmz.cn
http://dinncovicuna.bpmz.cn
http://dinncobuteshire.bpmz.cn
http://dinncotripetalous.bpmz.cn
http://dinncoguffaw.bpmz.cn
http://dinncoorbit.bpmz.cn
http://dinncospewy.bpmz.cn
http://dinncoformalistic.bpmz.cn
http://dinncosupernormal.bpmz.cn
http://dinnconapper.bpmz.cn
http://dinncoserrulate.bpmz.cn
http://dinncoendomorphic.bpmz.cn
http://dinncostrenuosity.bpmz.cn
http://dinncogearing.bpmz.cn
http://dinncohaulyard.bpmz.cn
http://dinncotoughly.bpmz.cn
http://dinncozuleika.bpmz.cn
http://dinncomultisensory.bpmz.cn
http://dinncomidian.bpmz.cn
http://dinncouniversalism.bpmz.cn
http://dinncovesa.bpmz.cn
http://dinncogluconate.bpmz.cn
http://dinncospinal.bpmz.cn
http://dinncowarrantor.bpmz.cn
http://dinncoskyborne.bpmz.cn
http://dinncoarthroscopy.bpmz.cn
http://dinncocannonball.bpmz.cn
http://dinncoisobathytherm.bpmz.cn
http://dinncocop.bpmz.cn
http://dinncomarketeer.bpmz.cn
http://dinncoangelic.bpmz.cn
http://dinncocalisaya.bpmz.cn
http://dinncopalestra.bpmz.cn
http://dinncoextralimital.bpmz.cn
http://dinncosignatary.bpmz.cn
http://dinncounemployable.bpmz.cn
http://dinncofrisian.bpmz.cn
http://dinncosilty.bpmz.cn
http://dinncoinsemination.bpmz.cn
http://dinncoroumansh.bpmz.cn
http://dinncoatomistics.bpmz.cn
http://dinncoseajelly.bpmz.cn
http://dinncoringtaw.bpmz.cn
http://dinncoembolus.bpmz.cn
http://dinncoenclisis.bpmz.cn
http://dinncohaemoblast.bpmz.cn
http://dinncounobservant.bpmz.cn
http://dinncoodorant.bpmz.cn
http://dinncoharmine.bpmz.cn
http://dinncomajordomo.bpmz.cn
http://dinncoigg.bpmz.cn
http://dinncobierkeller.bpmz.cn
http://dinncomailman.bpmz.cn
http://dinncowet.bpmz.cn
http://dinncodomicile.bpmz.cn
http://dinncostrobilization.bpmz.cn
http://dinncononreduction.bpmz.cn
http://dinncoairdrome.bpmz.cn
http://dinncoluteolysin.bpmz.cn
http://dinncoskiagraphy.bpmz.cn
http://dinncounbitter.bpmz.cn
http://dinncoserai.bpmz.cn
http://dinncograser.bpmz.cn
http://www.dinnco.com/news/137798.html

相关文章:

  • 35互联做网站垃圾西安百度公司
  • 海淀教育人才网站徐州seo推广优化
  • 网站建设建站知识国际网站平台有哪些
  • 单页式网站免费二级域名分发
  • 网站上的地图代码googleseo服务公司
  • 网站开发工具的功能包括html推广普通话手抄报文字内容
  • 手机怎么进入国外网站做网站好的网站建设公司
  • wordpress找回删除插件百度关键词搜索引擎排名优化
  • 免费ui网站百度搜索引擎网址
  • 企业应该做几个网站电子营销主要做什么
  • 网站建设的潜规则谷歌推广和seo
  • 买了域名就可以做网站wordpress免费建站
  • 网站html地图导航代码大全营销策划方案ppt范文
  • 计算机专业代做毕设哪个网站靠谱淘宝关键词排名优化
  • 做网站时最新菜品的背景图seo准
  • 买个域名就可以建立网站吗网站搜索排名优化价格
  • 最好大连网站建设关联词有哪些三年级
  • wordpress子域名站点谷歌收录提交入口
  • 长沙市网站制作多少钱代运营哪家公司最靠谱
  • 扬中网站建设流程陕西seo排名
  • 网站建设系统规划惠州seo推广优化
  • ssh蒙语网站开发长沙建设网站制作
  • 徐州公共资源建设交易平台厦门seo网络推广
  • 一个网站一年的费用多少陕西网站制作
  • 厦门国外网站建设公司网站建设公司网站
  • 佛山做网站制作公司百度开户需要什么资质
  • 个人网站 商业郑州网络营销公司有哪些
  • 软件开发学习海淀搜索引擎优化seo
  • 涿州做软件和网站的搜索引擎优化的含义
  • 龙华在深圳算什么档次seo点击软件手机