knrt.net
当前位置:首页 >> vBA遍历单元格并提取 >>

vBA遍历单元格并提取

假如在abc三列查找“张三”: set rng = columns("a:c").find("张三")'查找 if not rng is nothing then rng.select'如果找到就选中 凡是这三列单元格里第一个有“张三”两字的如“张三娃”等的单元格将被找到并选中,如果只能查找“张三”,前一句改一下即可: set rng = columns("a:c").find("张三", , , xlwhole)

首先要打开你需要的数个文件,而每个文件假设在vba所在工作簿的 a列,从a1开始,并且文件名排列下去,中间没有空白单元格,直到空白的单元格结束.需要求和的是每个文件内的shee1的a2单元格,最后合计数在程序所在文件的b1单元格

dim x as long x =activecell.row

Sub sdk() i = 1 For Each sc In Selection sc.Value = i i = i + 1 Next End Sub

为什么要遍历所有单元格呢,你查找指定的单元格就行了sub test() Dim i, j As IntegerFor i = 1 To 10000 '1000行最大 For j = 1 To 3 'A,B,C三列 If Cells(i, j).Value = "2012年度考核" ThenCells(i, j + 1) = "2012" '这里可以改为其他单元格的值 Cells(i, j + 2) = "5"End IfNextNext

Sub test() For Each c In ActiveSheet.Comments c.Parent.Interior.ColorIndex = 3 Next End Sub

Sub 按钮1_Click() Dim myRow As Single myRow = ActiveSheet.Cells(65536, 2).End(xlUp).Row ActiveSheet.Cells(myRow + 1, 2) = ActiveSheet.Range("A1") End Su

这段小程序就把一个EXCEL文件中每个工作表的A1单元格填上了a Sub tt() For i = 1 To ActiveWorkbook.Worksheets.Count ActiveWorkbook.Worksheets(i).Cells(1, 1).Value = "a" Next End Sub

代码完整一些:Private Sub CommandButton1_Click() Dim a, f, fNm, i, tmp With ActiveSheet a = .Range(.Cells(3, "D"), .Cells(31, "D")) End With fNm = "D:\我的文档\Desktop\aaaa.txt" f = Application.GetSaveAsFilename(fNm, "文本文

亲,由于很多信息都很含糊,所以没法写完整的代码,只能给个雏形,您自己修改了.Sub 遍历() Set fso = CreateObject("scripting.filesystemobject") Set ff = fso.getfolder("这里改成你的 指导文件夹 路径") For Each f In ff.Files If f.Name

zdhh.net | ldyk.net | tongrenche.com | fpbl.net | realmemall.net | 网站首页 | 网站地图
All rights reserved Powered by www.knrt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com