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「概念+ ...
随机推荐
- sublime python 配置内容
{"cmd": ["python", "-u", "$file"],"file_regex": &q ...
- 积性函数与Dirichlet卷积
转载自https://oi-wiki.org/math/mobius/ 积性函数 定义 若 $gcd(x,y)=1$ 且 $f(xy)=f(x)f(y)$,则 $f(n)$ 为积性函数. 性质 若 $ ...
- 【java异常】redis.clients.jedis.exceptions.JedisConnectionException: Could not get a res
产生此错误的原因通常是: 一.Redis没有启动: 我自己遇到一次这样的问题.汗! 二.由于防火墙原因无法连接到Redis; 1.服务器防火墙入站规则. 2.访问Redis的应用程序所在主机的出站规则 ...
- 10-day03-注释
Python注释 msg = “我爱你中国!” #单行注释使用 ''''''多行注释使用 print(msg) #this code is for >>>> ‘’‘print( ...
- GLIBC中的库函数fflush究竟做了什么?
目录 目录 1 1. 库函数fflush原型 1 2. FILE结构体 1 3. fflush函数实现 2 4. fclose函数实现 4 附1:强弱函数名 5 附2:属性__visibility__ ...
- 为什么要使用 Go 语言?Go 语言的优势在哪里?
golang主要特性 1.语法简单 舍弃语法糖,严格控制关键字 C++语法糖之多,令人发指,而C又太过于底层,容易出现自己造轮子的情况,如何在两者之间取舍,是每一个转向golang的工程师曾经思考过的 ...
- #ifndef #define #endif
在一个大的软件工程里面,可能会有多个文件同时包含一个头文件,当这些文件编译链接成一个可执行文件时,就会出现大量重定义的错误.在头文件中实用#ifndef #define #endif能避免头文件的重定 ...
- tcp & 长连接 短连接
参考文档: tcp协议 http://blog.chinaunix.net/uid-26833883-id-3627644.html 长连接和短连接 http://blog.csdn.net/free ...
- Guava cacha 机制及源码分析
1.ehcahce 什么时候用比较好:2.问题:当有个消息的key不在guava里面的话,如果大量的消息过来,会同时请求数据库吗?还是只有一个请求数据库,其他的等待第一个把数据从DB加载到Guava中 ...
- Configuration类的@Value属性值为null
今天写的Configuration类的@Value属性值为null @Configuration public class MybatisConfigurer { @Value("${spr ...