首先一个去除重复的简单例子
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