Excel VBA - 文本文件和文件夹操作实例集锦(4)
ElseIf temp <> Chr(34) Then str = str & temp End If Next i y = 0 x = x + 1 Loop Close #1
Application.ScreenUpdating = True End Sub
Sub fuz0619() '复制
' 蓝桥玄霜 2007-6-20 '
Dim Myr%, x%, n%, r1, Myc%, aa, res Dim Sht1 As Worksheet Dim Sht2 As Worksheet
Application.ScreenUpdating = False Set Sht1 = Sheets(1) Set Sht2 = Sheets(2) n = 2
Sht1.Activate
Myr = [a65536].End(xlUp).Row Sht2.Activate [b1] = 1: [c1] = 2
Range(\Sht1.Activate Call Uniquedata
For y = 0 To bb
For x = 3 To Myr + 1
If Sht1.Cells(x, 1) <> \
If Sht1.Cells(x, 1) = Sht1.Cells(y + 3, 8) Then
If Sht1.Cells(x, 1) <> Sht1.Cells(x - 1, 1) Then Sht2.Cells(n, 1) = Cells(x, 1) End If
aa = Cells(x, 2)
Set r1 = Sht2.Range(\ If Not r1 Is Nothing Then Myc = r1.Column
Sht2.Cells(n, Myc) = Cells(x, 3) End If Else
GoTo 100 End If End If 100:
Next x n = n + 1 Next y
Sht2.Activate
Myr = [a65536].End(xlUp).Row Range(\
Selection.NumberFormatLocal = \ Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _ Formula1:=\
Selection.FormatConditions(1).Interior.ColorIndex = 3 Application.ScreenUpdating = True End Sub
Sub Uniquedata() '不重复值
'引用自实战精粹
Dim Cel As Range, d, i%
Set d = CreateObject(\ Set Sht1 = Sheets(1) n = 3
Sht1.Activate
Myr = [a65536].End(xlUp).Row
For Each Cel In Sht1.Range(\ If Cel <> \
If Not d.exists(Cel.Value) Then d.Add Cel.Value, Cel.Value End If End If Next
res = d.Items
bb = UBound(res) For x = 0 To bb
Cells(n, 8) = res(x) n = n + 1 Next x End Sub
Sub qukh()
'去除表1空白行
'2007/6/20
Application.ScreenUpdating = False Set Sht1 = Sheets(1)
Myr = [a65536].End(xlUp).Row For x = 3 To Myr
If Left(Cells(x, 1), 1) <> \
Cells(x, 1).EntireRow.Delete shift:=xlUp Myr = Myr - 1: x = x - 1 If x > Myr Then Exit Sub End If Next x
Application.ScreenUpdating = True End Sub
11,按日期段和条件导出数据,另存为文件
‘http://www.excelpx.com/dispbbs.asp?boardID=5&ID=27397&page=1 ‘5550925.xls (自编宏之三) Option Explicit Dim x%, n1%
Dim Sht1 As Worksheet, Sht As Worksheet Sub daocu()
Dim ksrq As Date, jsrq As Date Dim ksnm$, jsnm$, n, nn, nm Dim Myr%, arr1, y%, i% Dim sFilenm$
Application.ScreenUpdating = False
If UserForm1.TextBox1.Value = \alue = \Set Sht1 = Sheets(\Sht1.Activate
Range(Cells(2, 1), Cells(2000, 26)).ClearContents ksrq = UserForm1.TextBox1.Value jsrq = UserForm1.TextBox2.Value n = DateDiff(\
ksnm = Right(Year(ksrq), 2) & Application.WorksheetFunction.Text(Month(ksrq), \jsnm = Right(Year(jsrq), 2) & Application.WorksheetFunction.Text(Month(jsrq), \ReDim nn(1 To n) ReDim nm(1 To n) For i = 1 To n If i = 1 Then
nm(1) = ksnm: nn(1) = CInt(ksnm) Else
nn(i) = nn(i - 1) + 1
If Right(nn(i), 2) = \
nm(i) = Application.WorksheetFunction.Text(nn(i), \ End If Next i n1 = 2
For i = 1 To UBound(nn) For Each Sht In Sheets
If Sht.Name = nm(i) Then Sht.Activate
Myr = [a65536].End(xlUp).Row For x = 2 To Myr
If Cells(x, 2) >= ksrq And Cells(x, 2) <= jsrq Then Call daocu1 n1 = n1 + 1 End If Next x End If Next Sht Next i
Sht1.Activate
Application.ScreenUpdating = True Sht1.Copy
sFilenm = Application.GetSaveAsFilename(filefilter:=\ActiveWorkbook.SaveAs sFilenm, xlText MsgBox \数据已导出! \End Sub
Sub daocu1() '选择导出 Dim xx%
For xx = 0 To 25
If UserForm1.ListBox1.Selected(xx) = True Then Cells(x, xx + 1).Copy Sht1.Cells(n1, xx + 1) End If Next xx End Sub
12,导出到多文本文件
Sub dcdwb()
'导出到文本文件 (自编宏之二) ‘请赐教0608.xls
‘http://club.excelhome.net/dispbbs.asp?boardID=2&ID=245438&page=1&px=0 '2007/6/8
Dim Filename$, Data$, aa$,Mypa$ Dim rows As Long, cols%
Dim i%, j%, Myr%, rr%, add%, n% Dim cell As Range
Application.ScreenUpdating = False Mypa = ThisWorkbook.Path & \Myr = [b65536].End(xlUp).Row: n = 2 Range(\
If [a1] = \★\Do Until ActiveCell.Row > Myr
Cells.Find(What:=\★\ rr = ActiveCell.Row
ActiveCell.Offset(-rr + n, 1).Resize(rr - n, 1).Select Set cell = Selection '选择数据 cols = cell.Columns.Count rows = cell.rows.Count
Filename = Mypa & aa & \ ‘文件名 Open Filename For Output As #1 For i = 1 To rows
Data = cell.Cells(i, cols) '一列数据
If IsEmpty(cell.Cells(i, cols)) Then Data = \ Print #1, (Data) '字符串型可去除\ Next i Close #1
ActiveCell.Offset(rr - n, -1).Resize(1, 1).Select aa = Cells(rr, 2).Text ‘文件名 n = rr + 1 Loop
Application.ScreenUpdating = True End Sub
Sub dcdwb2()
'导出到一个文本文件 '水平数据 '2007/6/8
Dim Filename$, Data$, aa$, Mypa$ Dim rows As Long, cols%, cols1% Dim i%, j%, Myr%, rr%, add%, n%
相关推荐:
- [高等教育]公司协助某村精准扶贫工作总结.doc
- [高等教育]高二生物知识点总结(全)
- [高等教育]苏教版数学三年级下册《解决问题的策略
- [高等教育]仪器分析课程学习心得
- [高等教育]2017年五邑大学数学与计算科学学院333
- [高等教育]人教版七年级下册语文第四单元测试题(
- [高等教育]2018年秋七年级英语上册Unit7Howmuchar
- [高等教育]2017年八年级下数学教学工作小结
- [高等教育]湖南省怀化市2019届高三统一模拟考试(
- [高等教育]四年级下册科学_基础训练及答案教材
- [高等教育]城郊煤矿西风井管路伸缩器更换施工安全
- [高等教育]昆八中20182019学年度上学期期末考试
- [高等教育]项目部各类人员任命书
- [高等教育]上市公司经营水务产业的模式
- [高等教育]人教版高二化学第一学期第三章水溶液中
- [高等教育]【中考物理第一轮复习资料】四.压强与
- [高等教育]金坑水电站报废改建工程机电设备更新改
- [高等教育]高中生物教学工作计划简易版
- [高等教育]2017年西华大学攀枝花学院(联合办学)44
- [高等教育]最新整理超短爆笑英文小笑话大全
- 优秀教师继续教育学习心得体会
- 阳历到阴历的转换
- 留守儿童教育案例分析
- 华师17春秋学期《玩教具制作与环境布置
- 测速传感器新型安装装置的现场应用
- 人教版小学数学三年级下册第四单元
- 创业个人意向书
- 山东省潍坊市2012年高考仿真试题(三)
- [恒心][好卷速递]四川省成都外国语学校
- 多少人错把好转反应当成了病情加重处理
- 中外广播电视史复习资料整理
- 江苏省扬州市江都区宜陵镇中学2014-201
- 工程造价专业毕业实习报告
- 广西师范学院心理与教育统计
- aympkrq基于 - asp的博客网站设计与开
- 建筑业外出经营相关流程操作(营改增后
- 人治 德治 法治
- [精华篇]常识判断专项训练题库
- 中国共产党为什么要实行民主集中
- 小学数学第三册第一单元试卷(A、B、C




