zoukankan      html  css  js  c++  java
  • VBS读取txt文档数据查找Excel中单元格数据符合条件的剪切到工作表2中

    Dim fso,f,a
    set oExcel = CreateObject( "Excel.Application" )
    oExcel.Visible = false
    '4) 打开已存在的工作簿:
    oExcel.WorkBooks.Open( "F:1.xlsx" )
    On Error Resume Next
    '判断是否存在Sheet2工作表,不存在新建
    If oExcel.WorkSheets("Sheet2") Is Nothing Then
        MsgBox "不存在,开始执行"
        oExcel.Worksheets.Add
    Else MsgBox "存在"
    End If
    '5) 设置第1个工作表为活动工作表:
    oExcel.WorkSheets("Sheet1").Activate
    '读取txt文档
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f=fso.OpenTextFile("D:UnexistFile.txt",1)
    '逐行读取并赋值到变量a,Do...loop循环
    DO While f.AtEndOfStream <> True
     i = 1
     a=f.ReadLine 
     'msgbox a 
     oExcel.WorkSheets("Sheet1").Activate
     
     Do while oExcel.Cells(i,4).Value <> "" '查找A列中所有的单元格
        '设置某个单元格中的数据赋值到变量
        'b=oExcel.Cells(i,4).Value
        'c=oExcel.Cells(i,17).Value
        d=oExcel.Cells(i,21).Value
        'e=oExcel.Cells(i,21).Value
        '判断单元格数据是否与txt数据相等
        if oExcel.Cells(i,4).Value = a then 'i是行,4是列
            'oExcel.Cells(i,4).font.color = vbred '设置字体底色为红色
            'msgbox "行"&i &"列"        
            oExcel.ActiveSheet.Range("A" & i & ":" & "X" & i).Cut
            oExcel.WorkSheets("Sheet2").Activate
            oExcel.ActiveSheet.Range("A1:X1").Insert
            oExcel.WorkSheets("Sheet1").Activate
            oExcel.ActiveSheet.Rows(i).Delete
    
        ElseIf Instr(b,a)>1 then  '判断txt的数据是否被包含在单元格中
            'msgbox "行"&i &"列"        
            oExcel.ActiveSheet.Range("A" & i & ":" & "X" & i).Cut
            oExcel.WorkSheets("Sheet2").Activate
            oExcel.ActiveSheet.Range("A1:X1").Insert
            oExcel.WorkSheets("Sheet1").Activate
            oExcel.ActiveSheet.Rows(i).Delete
        Elseif oExcel.Cells(i,22).Value = a then
            'msgbox "行"&i &"列"        
            oExcel.ActiveSheet.Range("A" & i & ":" & "X" & i).Cut
            oExcel.WorkSheets("Sheet2").Activate
            oExcel.ActiveSheet.Range("A1:X1").Insert
            oExcel.WorkSheets("Sheet1").Activate
            oExcel.ActiveSheet.Rows(i).Delete
            'EXIT do
        
        end if
        i = i+1
     loop
    
    loop
    
    oExcel.ActiveWorkBook.Save
    oExcel.WorkBooks.Close
    oExcel.Quit
    set oExcel = nothing
    msgbox "操作完成"
  • 相关阅读:
    React Native 开发豆瓣评分(三)集成 Redux
    React Native 开发豆瓣评分(二)路由配置
    React Native 开发豆瓣评分(一)环境搭建&配置模拟器
    VSCode 搭建 React Native 环境
    webpack4 + ejs 构建多页应用
    react-native 沉浸式状态栏
    react-native——tab配置及跳转
    uni-app 入门之 nvue (weex) 爬坑记
    javascript中bind()、call()、apply()的使用
    mysql数据库中文乱码配置文件解决以及常见mysql命令
  • 原文地址:https://www.cnblogs.com/liuliu-word/p/7434891.html
Copyright © 2011-2022 走看看