excel

1.快速查找重复值

重复的个数统计

2.copy不重复的值

3.快速转置, 行列转换

4.vba 下拉多选

支持VBA的文件要保存成xlsm格式,不是通常的xlsx
https://www.cnblogs.com/yszzu/diary/2019/08/14/11350660.html

  • 4.1表单控件:

使用宏命令发送快捷键, 比如Ctrl+P Ctrl+N

see Office VBA API

磅的大小为 1/72 英寸。 字号通常用磅衡量。 比如5号字就是5磅

Alt+F11打开编译框
Alt+F8 打开运行框, 然后可以选择要运行的方法
F8 开始调试 先选中function
F5 直接运行

单元格中的图片不能用单元格直接引用,需要用shape对象操作, shape又需要使用shapes(n)来获取引用

Sub xx图片右移10磅()
Set myDocument = Worksheets(1)
myDocument.Shapes(1).IncrementLeft 10


End Sub
点击查看代码
'Wait one second before changing the color again
    NextBlink = Now + TimeSerial(0, 0, 1)
    Application.OnTime NextBlink, "StartBlinking", , True   
	
'最后这个True 表示启用此任务	
Workbooks("Book1").Sheets("Sheet1").Range("A1:D5")

Workbooks("Book1").Sheets("Sheet1").Range("A:D")

Workbooks("Book1").Sheets("Sheet1").Range("A1")

多个区域可以用Union(xx, xxx)
  • 4.5 插入图片 调试
Sub 插入图片x()
Set myDocument = Worksheets(1)

'遍历删除所有图片, 不能用for i to xx.count
'https://learn.microsoft.com/zh-cn/office/vba/language/reference/user-interface-help/for-eachnext-statement
For Each shapexx In myDocument.Shapes()
    namexx = shapexx.Name
    'https://learn.microsoft.com/zh-cn/office/vba/api/office.msoshapetype
    If shapexx.Type = 11 Or shapexx.Type = 13 Or shapexx.Type = 28 Then
        shapexx.Delete
    End If
Next
        
zhuanghao = CStr(myDocument.Range("G2"))
        
file_path = Application.ActiveWorkbook.Path + "\"
myDocument.Shapes.AddPicture _
    file_path + zhuanghao + "左.jpg", _
    True, False, 20, 150, 330, 300

myDocument.Shapes.AddPicture _
    file_path + zhuanghao + "右.jpg", _
    True, False, 380, 150, 330, 300
    
End Sub

找不到某个属性的时候,可以点开加号查看所有属性

没有try catch语句,可以使用on error go to xxx处理

4.5.1 copy数据到目标sheet 并连续打印

Sub PrintEvery10RowsWithTemplate()
    Dim ws As Worksheet, tempWs As Worksheet
    Dim startRow As Integer, endRow As Integer
    Dim totalRows As Integer, stepSize As Integer
    Dim destRow As Integer
    Dim lastRow As Integer
    
    ' Set your main worksheet
    Set ws = ActiveSheet
    Set tempWs = ThisWorkbook.Sheets("TempPrint")
    
    ' Define data range
    totalRows = 15 ' Adjust based on data size
    stepSize = 5   ' Print every n rows
    
    ' Find where template rows start in TempPrint
    lastRow = tempWs.Cells(Rows.Count, 1).End(xlUp).Row ' Find last used row
    
    ' Loop through data in steps of 10
    For startRow = 1 To totalRows Step stepSize
        endRow = startRow + stepSize - 1
        
        ' Clear only the top section of TempPrint (keep template rows)
        tempWs.Rows("1:" & stepSize).ClearContents
        
        ' Copy 10-row chunk to TempPrint (before the template rows)
        ws.Rows(startRow & ":" & endRow).Copy
        tempWs.Rows(1).PasteSpecial Paste:=xlPasteValues  ' only copy value, no format and formulas, see https://learn.microsoft.com/en-us/office/vba/api/excel.xlpastetype
        
        ' Print TempPrint (entire sheet including template rows)
        tempWs.PrintOut ' Use tempWs.Select to test before printing
        
    Next startRow
    
    MsgBox "Printing complete!", vbInformation, "Done"
End Sub

  • 4.5 和python, DataBase的对比
    VBA处理千条以上的数据就很吃力,动辄几十秒甚至上分钟才能跑出结果,期间excel假死一样。
    python 会快点, 但要有编程经验才能用起来。
    DB 轻松处理大批量数据,从excel导入到DB, 需要清理数据格式。 MySQL支持中文列名,开源的客户端DBeaver支持导入csv并自动创建表和列。

安装运行环境、依赖包, 往往需要FQ。
所以写代码不一定是最快的处理方式, 如果小批量的处理,手动统计可能还更快。

5. VLOOKUP, OFFSET, IFS

IFS需要excel 2019之后的版本才会有 下载地址msdn i tell you + office Tool plus kms.03k.org
名称管理器--图片引用 公式的特点 =INDEX(YC定位图!$C:$C,检验批!$V$5,0)

AND的使用: IF(AND(xxx>1, xxx<2), a, b) 而不是IF(1<xxx<2, a,b) 虽然它不报错,但是无效,也不是IF(xxx>1 AND xxx>2, a,b) 报错。

5.1 公式中使用双引号

字符串是用""括起来, 里面也有双引号,此时用"当转义符,变成"""", 相当于java中的"\""

6. 根据cell value改变单元格颜色

https://support.microsoft.com/en-us/office/use-conditional-formatting-to-highlight-information-fed60dfa-1d3f-4e13-9ecb-f1951ff89d7f#ID0EDH=Web

7.数据对比 视图

使用excel缺点:
1.慢,
2.格式长度必须固定(扩展麻烦)
3. 解析和操作都容易出错

优点:
多个sheet里的单元格可以任意引用,并自动计算所有的公式内容, 甚至可以跨文件引用
添加删除列时 相关公式自动更新引用坐标

posted @   funny_coding  阅读(214)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
build beautiful things, share happiness
点击右上角即可分享
微信分享提示