typeName基本是一个通用的方法
Sub test()
Dim b As String
b = "2012-12-12"
Debug.Print TypeName(CDate(b))
End Sub
Sub test()
Dim a As Integer
a = 123
Dim b
b = 12304
Debug.Print Format(a, "0000.00")
Debug.Print Format(a, "\价格\ 0000.00")
Debug.Print Format(b, "yyyy-mm-dd")
End Sub
'output
0123.00
价格 0123.00
1933-09-07
Sub test()
Debug.Print Date
Debug.Print Time
Debug.Print Now
Debug.Print Timer
End Sub
'output:
04.09
15:31:01
04.09 15:31:01
55861.21
Sub test()
Debug.Print Format(Now, "aaa")
Debug.Print Format(Now, "aaaa")
Debug.Print Format(Now, "ddd")
Debug.Print Format(Now, "dddd")
Debug.Print Format(Now, "yy-mm-dd")
End Sub
'output
周四
星期四
Thu
Thursday
20-04-09
Sub test()
Debug.Print DateSerial(2021, 12, 12)
Debug.Print TimeSerial(15, 12, 12)
End Sub
Sub test()
Debug.Print Year(Now)
Debug.Print Month(Now)
Debug.Print Day(Now)
Debug.Print Hour(Now)
Debug.Print Minute(Now)
Debug.Print Second(Now)
End Sub
Sub test()
Dim a, b As Date
a = #12/12/2020#
b = "2020-12-31"
Debug.Print "相隔" & (b - a) & "天"
Debug.Print "相隔" & DateDiff("d", a, b) & "天"
Debug.Print "相隔" & DateDiff("q", a, b) & "季"
Debug.Print "相隔" & DateDiff("w", a, b) & "周"
Debug.Print "相隔" & DateDiff("n", a, b) & "分"
End Sub
Sub test()
Dim a, b As Date
a = #12/12/2020#
b = "2020-12-31"
Debug.Print DateAdd("d", 1, b) & "天"
Debug.Print DateAdd("q", 1, b) & "季"
Debug.Print DateAdd("n", 120, b) & "分"
End Sub
Dim k As Boolean
Sub test()
If k Then
k = False
Exit Sub
End If
Range("a1") = Format(Now, "hh:mm:ss")
Application.OnTime Now + TimeValue("00:00:01"), "test"
End Sub
Sub stop1()
k = True
End Sub
Sub hah()
Dim rg As Range
Set rg = Range("b1:b10")
For Each r In rg
With ActiveSheet.CheckBoxes.Add(r.Left, r.Top, r.Width, r.Height)
.Characters.Text = "是"
.Value = xlOff
.LinkedCell = r.Address
.Display3DShading = False
End With
Next r
End Sub
Set myDocument = Worksheets(1)
With myDocument.Shapes.AddShape(msoShapeRectangle, _
144, 144, 72, 72)
.Name = "Red Square"
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Line.DashStyle = msoLineDashDot
End With
Sub hr()
Dim rg
Dim num As Integer
rg = Range("a1:a12")
For i = 1 To 12
If i = 12 Then
Cells(i, 3) = Cells(1, 1)
Cells(1, 1).Interior.ColorIndex = 3
Exit Sub
End If
num = (Rnd() * (UBound(rg) - 1) + 1) \ 1
Range("c" & i) = rg(num, 1)
tmp = Cells(num, 1)
Cells(num, 1) = Cells(UBound(rg), 1)
Cells(UBound(rg), 1) = tmp
Cells(UBound(rg), 1).Interior.ColorIndex = 3
rg = Range("a1:a" & (UBound(rg) - 1))
Next i
End Sub
rg(1,1) = 12
等方法直接对单元格进行操作,下面没有加 set 得到仅仅就是一个取单元格区域的数组,通过rg2(1,1) = 12
仅仅对数组有效对单元格不会有任何影响set rg = range("a1:a12")
rg2 = range("a1:a12")
application.screenupdating = false