excel 宏循环行数据 ,Excel统计所有sheet数据行数 VBA
Sub fun1()
'统计每一个sheet有多少行数据
Set s1 = Sheets("Sheet1")
'totalok = 0
For i = To Sheets.Count
s1.Cells(i, ) = Sheets(i).Name
r = Sheets(i).Range("A65535").End(xlUp).Row s1.Cells(i, ) = r
If i > Then
totalok = totalok + r
End If
Next
s1.Cells(, ) = totalok
End Sub
Sub Fun2()
'一个sheet表中循环查另一个sheet中是否存在,
‘查地名是否存在 OK 'Set Sheet = Worksheets("Sheet251")
Set dbSH = Sheets("pd_port")
'Set newSH = Sheets("(CN) CHINA") Cells(, ) = Now() ' 开始时间
Dim i
i =
Do While Cells(i, ) <> "" newCode = Trim(UCase(Cells(i, )))
newName = Trim(UCase(Cells(i, ))) isAirPort = ""
isSeaPort = ""
isRailway = ""
PortType = ' 0港口,1机场,2火车站 3其他 If InStr(newName, " APT") > Then
isAirPort = "Yes AirPort"
PortType =
End If
If InStr(newName, " PT") > Then
isSeaPort = "Yes SeaPort"
PortType =
End If
If InStr(newName, " RAILWAY") > Then
isRailway = "Yes Railway"
PortType =
End If r1 = "code No"
r2 = "name No"
For j = To
dbCode = Trim(UCase(dbSH.Cells(j, )))
dbName = Trim(UCase(dbSH.Cells(j, ))) If PortType = Then
dbName = Replace(dbName, " Apt", " AIRPORT") newCode = Right(newCode, )
newName = Replace(newName, " Apt", "")
End If If dbCode = newCode Then
r1 = "code Exist"
End If If dbName = newName Then
r2 = "name Exist"
End If
Next Cells(i, ) = r1
Cells(i, ) = r2 Cells(i, ) = isAirPort
Cells(i, ) = isSeaPort
Cells(i, ) = isRailway
Cells(i, ) = PortType
i = i +
Loop Cells(, ) = Now() ' 结束时间
End Sub
Sub Fun3()
'一个sheet表中循环查另一个sheet中是否存在,
’查地名是否存在 test 'Set Sheet = Worksheets("Sheet251")
Set dbSH = Sheets("pd_port")
'Set newSH = Sheets("(CN) CHINA") Cells(, ) = Now() ' 开始时间
Dim i
i =
'Do While Cells(i, 2) <> ""
For i = To
newCode = Trim(UCase(Cells(i, )))
newName = Trim(UCase(Cells(i, ))) isAirPort = ""
isSeaPort = ""
isRailway = ""
PortType = ' 0港口,1机场,2火车站 3其他 If InStr(newName, " APT") > Then
isAirPort = "Yes AirPort"
PortType =
End If
If InStr(newName, " PT") > Then
isSeaPort = "Yes SeaPort"
PortType =
End If
If InStr(newName, " RAILWAY") > Then
isRailway = "Yes Railway"
PortType =
End If r1 = "code No"
r2 = "name No"
For j = To
dbCode = Trim(UCase(dbSH.Cells(j, )))
dbName = Trim(UCase(dbSH.Cells(j, ))) If PortType = Then
dbName = Replace(dbName, " Apt", " AIRPORT") newCode = Right(newCode, )
newName = Replace(newName, " Apt", "")
End If If dbCode = newCode Then
r1 = "code Exist"
End If If dbName = newName Then
r2 = "name Exist"
End If
Next Cells(i, ) = r1
Cells(i, ) = r2 Cells(i, ) = isAirPort
Cells(i, ) = isSeaPort
Cells(i, ) = isRailway
Cells(i, ) = PortType
'i = i + 1
'Loop
Next
Cells(, ) = Now() ' 结束时间
End Sub
Sub Fun4()
' 查国家是否存在 ' Set Sheet = Worksheets("Sheet251")
Set dbSH = Sheets("pd_country")
Set newSH = Sheets("Country Name")
newSH.Cells(, ) = Now() ' 开始时间 For i = To
' Sheet.Rows(i).Cells (0)
' Print Sheet.Cells(i, 1)
' Print Worksheets("Sheet251").Cells(i, 1).Value
newCode = UCase(newSH.Cells(i, ))
newName = UCase(newSH.Cells(i, )) ResultCode = "code No"
ResultName = "name No"
For j = To
dbCode = UCase(dbSH.Cells(j, ))
dbName = UCase(dbSH.Cells(j, )) ' MsgBox dbValue + "---" + newValue
If dbCode = newCode Then
ResultCode = "code Exist"
End If If dbName = newName Then
ResultName = "name Exist"
End If Next newSH.Cells(i, ) = ResultCode
newSH.Cells(i, ) = ResultName newSH.Cells(, ) = Now() ' 结束时间
Next
End Sub
Sub stoCheckTable()
msg = "一.请确保【申通账单】表格与【HELKA导出寄件数据】表格已准备;"
msg = msg + vbCrLf + "二.请确保第1个表格为【申通账单]表格】;"
msg = msg + vbCrLf + "三.请确保第2个表格为【HELKA导出寄件数据】表格;"
msg = msg + vbCrLf + "四.点[是]开始核对数据!"
msgResult = MsgBox(msg, vbYesNo, "申通快递数据核对")
If msgResult = Then
Set stoTable = Sheets() '申通账单表格
Set helkaTable = Sheets() 'HELKA导出的表格
stoIndex = ' 申通的表格 第几行开始循环
NotFoundCount = '几条没有找到数量统计
Do While stoTable.Cells(stoIndex, ) <> ""
stoNo = Str(Trim(stoTable.Cells(stoIndex, )))
helkaIndex = 'HELKA导出的表格 第几行开始循环
okIndex =
Do While helkaTable.Cells(helkaIndex, ) <> ""
TempNo = Trim(helkaTable.Cells(helkaIndex, ))
If TempNo <> "" Then
helkaNo = Str(Trim(helkaTable.Cells(helkaIndex, )))
If (stoNo = helkaNo) Then
'MsgBox "找到了" + stoNo + "=" + helkaNo + "__ helkaIndex:" + Str(helkaIndex)
okIndex = helkaIndex
Exit Do
End If
End If
helkaIndex = helkaIndex +
Loop
If okIndex > Then
stoTable.Cells(stoIndex, ) = "核对成功"
stoTable.Cells(stoIndex, ) = helkaTable.Cells(okIndex, )
stoTable.Cells(stoIndex, ) = helkaTable.Cells(okIndex, )
stoTable.Cells(stoIndex, ) = helkaTable.Cells(okIndex, )
Else
NotFoundCount = NotFoundCount +
stoTable.Cells(stoIndex, ) = "不存在"
stoTable.Cells(stoIndex, ).Interior.ColorIndex =
End If
stoIndex = stoIndex +
Loop
If NotFoundCount > Then
stoTable.Cells(stoIndex, ) = "核对结果"
stoTable.Cells(stoIndex, ) = "状态"
stoTable.Cells(stoIndex, ) = "物品名称"
stoTable.Cells(stoIndex, ) = "备注"
MsgBox "共发现" + Str(NotFoundCount) + " 条不存在的数据!"
Else
MsgBox "核对完成,所有单号都找到!"
End If
End If
End Sub
excel 宏循环行数据 ,Excel统计所有sheet数据行数 VBA的更多相关文章
- Excel宏录制、数据透视表、合并多个页签
前段时间做数据分析的时候,遇到很多报表文件需要处理,在此期间学习了很多Excel操作,特此做笔记回顾. Excel宏录制 打开开发者工具 打开Excel文件,选择”文件”-->“选项”--> ...
- 原创:如何实现在Excel通过循环语句设置指定行的格式
原创:如何实现在Excel通过循环语句设置指定行的格式 一.需求: 想让excel的某些行(比如3的倍数的行)字体变成5号字 如何整: 二.实现: Sub code() To Range(" ...
- Pandas写excel总结:写入多个sheet、1个sheet写入多行、向已有sheet追加数据
1.最简单最基础的写:1excel1sheet df.to_excel("test.xlxs") 2.在一个excel文件里面写入多个sheet writer=pd.ExcelWr ...
- excel宏整理
工作以后发现excel很强大,用好excel已经成功工作中很重要的一部分内容,最近写了一些宏, 整理如下: 根据excel生成sql脚本的sc_template Sub GenSCTemplateFi ...
- 向excel中循环插入值
import xlrd #导入excel读模块 from xlutils import copy #导入copy模块 book = xlrd.open_workbook('tb_base_buildi ...
- POI导出复杂的excel;excel公共样式类;excel拼接定制类;数据科学计数法转为普通值
一.excel公共样式类(包含数据科学计数法转为普通值) package com.thinkgem.jeesite.common.utils.excel; import org.apache.poi. ...
- C#中NPOI操作excel之读取和写入excel数据
一.下载引用 下载需要引用的dll,即:NPOI.dll,NPOI.OOXML.dll,NPOI.OpenXml4Net.dll,ICSharpCode.SharpZipLib.dll(office2 ...
- C# Excel数据验重及Table数据验重
http://blog.csdn.net/jiankunking/article/details/38398087 最近在做导入Excel数据的时候,要检验数据是否重复: 1.要检验Excel数据本身 ...
- SpringBoot图文教程10—模板导出|百万数据Excel导出|图片导出「easypoi」
有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1「概念+ ...
随机推荐
- 采坑复盘:logging日志能用封装后的函数来打日志,发现filename一直显示封装logging函数的方法所在的文件名
问题: logging日志能用封装后的函数来打日志,发现filename一直显示封装logging函数的方法所在的文件名 原因: logging记录的是第一个函数执行所在的文件,那用封装的函数,首先执 ...
- qt中窗体全屏
原文地址:https://www.cnblogs.com/wiessharling/p/3750461.html 近期在学习QT时遇到了很多问题这也是其中一个,个人通过在各种书籍和网络上的查阅找到了一 ...
- Codeforces Round 564 题解
很抱歉让标题把您骗进来了. 这是一场打得最失败的div1. 作为一个橙名一题都不会…… 旁边紫名的PB怒切3题,div2的也随便玩玩出了div1b/div2d…… 这名字颜色也太有水分了. 也就只会2 ...
- QAbstractItemModel详细剖析 …&&... QAbstractTableModel
从函数开始: QModelIndex QAbstractTableModel::sibling(int row, int column, QModelIndex &idx) const; ...
- Java 并发系列之三:java 内存模型(JMM)
1. 并发编程的挑战 2. 并发编程需要解决的两大问题 3. 线程通信机制 4. 内存模型 5. volatile 6. synchronized 7. CAS 8. 锁的内存语义 9. DCL 双重 ...
- Java 并发系列之一:java 并发体系
1. java 并发机制的底层原理实现 1.1 volatile 1.2 synchronized 1.3 原子操作 2. java 内存模型(JMM) 3. java并发基础线程 4. java ...
- python 项目实战之备份文件夹并且压缩文件夹及下面的文件
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/11/12 14:21 # @Author : zoulixiang # @S ...
- Failed to contact the endpoint at http://controller:35357/ for discovery. Fallback to using that endpoint as the base url.
问题描述 openstack安装过程中,执行 openstack domain create --description "Domain" example 报错如下: Failed ...
- 在Github或Gitee上用hexo搭建个人博客
安装nodejs环境查看node版本node -v 安装cnpmnpm install cnpm -g --registry=https://registry.npm.taobao.org 安装 He ...
- 修改mysql存储过程或函数的定义着
以root用户登录mysql控制台 (1)首先查询 mysql> select definer from mysql.proc; (2)然后根据条件进行更新 update mysql.proc ...