Vba总结

首先一个去除重复的简单例子

Sub test1()
    MsgBox Cells(2, 8).Value
    Dim i As Integer
    Dim j As Integer
    For i = 2 To 355
        For j = i + 1 To 355
            If Cells(i, 8).Value = Cells(j, 8).Value Then
                Cells(j, 8).Value = "此项重复,已经把它删除了"
            End If
        Next
    Next
End Sub

1、获取某一列的行数

ActiveSheet.Range("A65535").End(xlUp).Row

2、获取某一行的列数

ActiveSheet.Range("IV1").End(xlToLeft).Column

3、给某一个sheet的某一个位置写上数据

Sheets("Sheet2").Cells(i, 1).Value = value

4、获取二维数组的长度和宽度

row = UBound(arr,1)
col = UBound(arr,2)

5、动态数组的创建:

Dim arrSheetName()
ReDim arrSheetName(1 to value) or ReDim arrSheetName(x to y , m to n)

当然了 使用redim preserve可以动态的增加数组的大小,并且不破坏之前的数据

6、Function 返回数据
定义一个函数

Function func1()
	Dim result()
	\\todo...
	func1 = result()
End Function

在main函数中获取数据

Function Main()
	result = func1()
End Function

7、将特定格式的字符串转化为日期类型

trueTime = "2020-01-01 20:46"
CurrentDateTimeString = Format$(Date, "yyyy-MM-dd HH:MM")
typeTime = CDate(trueTime)
MsgBox typeTime

8、日期计算:
8.1、百度/google:TimeValue用法
8.2、百度/google:DateDiff 函数用法
范例:

	CurrentDateTimeString = Format$(Date, "yyyy-MM-dd HH:MM")
	time1 = CDate(time1)
	time2 = CDate(time2)
	MsgBox time1
	MsgBox time2
	interval = DateDiff("n", time1, time2)
	MsgBox interval
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值