1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| Sub main()
Dim wb As Workbook Dim ws As Worksheet Dim file As String file = "C:\Users\25276\Desktop\test.xlsx" Set wb = Workbooks.Open(file) Set ws = Worksheets("JasonQian") ws.Activate handleElement ws End Sub
Sub modifyElement(ByRef ws As Worksheet) ws.Name = "JasonQian" ws.Cells(2, 3).Value = "Cells(2, 3)" ws.Range("A1").Value = "Range('A1')" ws.Range("A2:B4").Value = "Range('A2:B4')" Dim rng As Range Set rng = ws.UsedRange ws.Rows(2).Hidden = False ws.Columns(3).Delete ws.Cells.ClearContents ws.Range("A3:B3").ClearContents End Sub
Function rowsCount(ByVal ws As Worksheet) As Long Dim rc As Long rc = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row rowsCount = rc End Function
Sub forOperator(ByVal ws As Worksheet) Dim rc As Long rc = rowsCount(ws) For i = 1 To rc Debug.Print i Next i End Sub
Sub IfOeprator(ByVal ws As Worksheet) Dim rc As Long rc = rowsCount(ws) If rc > 10 Then Debug.Print "G" Else Debug.Print "GG" End If End Sub
Function CountDots(cellValue As String) As Integer Dim dotCount As Integer dotCount = Len(cellValue) - Len(Replace(cellValue, ".", "")) CountDots = dotCount + 1 End Function
|