Professional Documents
Culture Documents
html
t
e
n
.
p
Excel
Excel
i
t
l
e
c
x
e
.
w
Excel
Excel
Excel Excel
Excel
MVP
http://www.exceltip.net/forum-75-1.html
x III x
t
e
n
.
p
Excel http://www.exceltip.net
i
t
l
e
c
x
e
.
w
Excel
Excel
Excel
Excel Excel
Business Intelligence
Excel
Excel
x IV x
http://www.exceltip.net/forum-75-1.html
t
e
n
.
p
i
t
l
e
c
x
e
.
w
Excel
ExcelTip.Net
Excel
Excel
http://www.exceltip.net/forum-75-1.html
xVx
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
Excelpx.com
Excel
ExcelTip.Net
Officefans.net
andyxie
Excel
Excel Excel
MVP chenjun
Excel
Excel Excel
MVP
Excel
Excel
MVP BIN_YANG168
Excel 2010 Office
MVP
x VI x
http://www.exceltip.net/forum-75-1.html
Excel
Excel
MVP northwolves
VBA
VBA VBA
VBA
t
e
n
.
p
VBA VBA
i
t
l
e
c
x
e
.
w
Excel
EN/R
http://www.exceltip.net/forum-75-1.html
x VII x
t
e
n
.
p
i
t
l
e
c
x
e
.
w
7.0 VBA
MVP
MVP
Excel
VBASQL in Excel
MVP
Excel 2010
Excel 2010
Excel 2010 VBA
Excel 2010
SQL in Excel 2010
Excel
Excel
x VIII x
http://www.exceltip.net/forum-75-1.html
Microsoft Office Excel 2010
Excel 20032007 2010
xls xlsm xla
xlam Excel 20032007 2010
t
e
n
.
p
250 1 VBA
VBA VBA
VBA
i
t
l
e
c
x
e
.
w
VBA
VBA
11 10
3
VBA
VBA
2
4
3
7
VBA
Excel VBA
http://www.exceltip.net/forum-75-1.html
x IX x
4
2
5
3
Excel
6
t
e
n
.
p
2
VBA
i
t
l
e
c
x
e
.
w
w
8
21 VBA
4 ActiveX
Excel 6
10
3 DLL
VBA
11
PDF PDF
Excel
xXx
http://www.exceltip.net/forum-75-1.html
Ctrl+Shift+Enter
Ctrl Shift Enter
t
e
n
.
p
VBA VBA
i
t
l
e
c
x
e
.
w
Excel
VBA
y
WIN XPVISTA
WIN 7 Excel 20032007 2010
http://www.exceltip.net/forum-75-1.html
x XI x
Range("A1:D10")
ActiveSheet.UsedRange ActiveCell.CurrentRegion
t
e
n
.
p
VBA
i
t
l
e
c
x
e
.
w
Excel VBA
Excel VBA
Excel VBA
VBA Excel
VBA
Excel ExcelTip.Net
BUG
http://www.exceltip.net/forum-75-1.html
QQ
Excel
8 8 8
x XII x
http://www.exceltip.net/forum-75-1.html
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
7
Connect &
Excel VBA
8.0
1
8.0 VBA
http://excelbbx.cn/
105 Excel 50
QQ
ExcelTip.Net
http://www.exceltip.net/forum-75-1.html
x XIII x
Excelpx.com Officefans.net
12348910 11
567
t
e
n
.
p
i
t
l
e
c
x
e
.
w
2010 8 28
------------------------------------------------------------------------------------------------------------------------
x XIV x
http://www.exceltip.net/forum-75-1.html
1
1.1
t
e
n
.
p
........................................................................................................................................1
...................................................................................................................................1
i
t
l
e
c
x
e
.
w
w
1.2
1.3
.................................................................................... 1
.................................................................................................... 4
............................................................ 5
.................................................................................................... 6
................................................ 6
ShellExecute ...................................................................... 8
...................................................................................................................................8
........................................................................................................... 9
................................................................................................................ 9
VBA .................................................................... 10
Error .................................................................................... 12
.......................................................................... 13
...................................................................................................... 14
......................................................................................................... 15
VBA .................................................................................... 17
.................................................................. 17
Err.Number .......................................................................... 19
................................................................................................................................. 19
.......................................................................................... 19
ScreenUpdating ........................................................................... 20
10 .................................................................................... 21
With ........................................................................................... 22
11
........................................................................................ 22
..................................................................... 23
12 B ............................................................................ 23
Select ..................................................................................... 24
http://www.exceltip.net/forum-75-1.html
x XV x
1.4
13
................................................................................... 25
VBA .................................................................................................. 26
14
........................................................................................... 26
................................................................................ 27
15
........................................................................ 27
................................................................ 28
16
........................................................................ 28
................................................................................................ 29
17
............................................................................... 30
.................................................................................... 31
18
IP .............................................................................. 31
........................................................................................................ 32
t
e
n
.
p
........................................................................................................................ 32
i
t
l
e
c
x
e
.
w
w2
1.5
19
....................................................................................... 33
VBA .......................................................................................... 33
20
........................................................................................... 34
........................................................ 37
21
Excel ........................................................................................ 37
Excel ................................................................................................. 39
22
................................................................................... 40
API ............................................................ 41
23
................................................................................... 41
.................................................................................... 42
..................................................................................................................................... 42
...................................................................................................................................... 44
2.1
x XVI x
......................................................................................................................................... 44
24
........................................................................... 44
Union .................................................................................... 46
25
........................................................................... 47
Find ................................................................................................ 49
26
................................................................................................... 50
KeyUp ............................................................................... 52
27
................................................................................................... 53
FindFormat ............................................................................................ 54
28
................................................................................................... 54
........................................................................................................ 55
29
# ..................................................................................... 56
http://www.exceltip.net/forum-75-1.html
..................................................................................... 57
30 ........................................................ 57
Datedif .......................................................................................... 59
31 ........................................................ 59
Microsoft Forms 2.0 Object Library........................................ 60
32 ................................................................................ 61
lookat ................................................................................. 63
33 ................................................................................ 63
Collection ....................................................................................... 65
t
e
n
.
p
34 ........................................................ 65
MergeArea ................................................................... 67
35 ............................................................................................ 67
VBA ....................................................... 68
i
t
l
e
c
x
e
.
w
w
2.2
............................................................................................................................ 69
36 ................................................................................ 69
ActionControl.......................................................................... 72
37 .................................................................... 73
SpecialCells ....................................................................... 74
38 .................................................................................... 74
................................................................. 76
39 ................................................................ 76
[] ....................................................... 77
40 ........................................................ 77
xlSheetVisible ........................................................ 78
41 ................................................................................ 79
Target Activecell ....................................................................................... 80
42 ................................................................ 80
OnTime ..................................................................................... 82
2.3
............................................................................................................................ 82
43 ............................................................................................ 82
DIR ............................................................................ 83
44 ................................................................................ 84
FileDialog .............................................................................................. 85
45 3 ............................................................................. 86
CopyFile ......................................................................................... 88
46 Excel XPS PDF .......................................................... 88
PrintOut XPS ........................................................ 90
47 .................................................... 91
FileExists ................................................................... 92
http://www.exceltip.net/forum-75-1.html
x XVII x
2.4
48
.MP3 ..................................................... 92
................................................................................................ 94
49
................................................ 95
........................................................................ 96
............................................................................................................................ 96
50
................................................................................... 96
DrawingObjects Shape ..................................................................... 97
51
.................................................................... 97
............................................................................ 98
t
e
n
.
p
52
Selection .................................................................................................... 99
vlookup ........................................................................ 99
53
.............................................................................. 101
.................................................................. 101
i
t
l
e
c
x
e
.
w
2.5
3
3.1
3.2
x XVIII x
.................................................................................................................................... 104
................................................................................................................................... 104
54
55
............................................................................................................. 105
MOD SpecialCells ...................................................................... 106
56
............................................................................. 107
SpecialCells ................................................................................ 108
57
...................................................... 109
Change ..................................... 110
58
.......................................................... 110
VBA ......................................................................................... 111
59
................................................................................. 112
Find ..................................................... 113
60
......................................................................... 113
VBA ............................................................................. 115
61
............................................................................................. 115
...................................................................................................... 116
................................................................................................................. 116
62
.................................................. 116
StrConv ............................ 117
63
.................................................................. 118
http://www.exceltip.net/forum-75-1.html
................................................................................... 119
64 .................................................................. 120
R1C1 ......................................................................................... 121
65 .............................................. 122
Like .............................................................. 123
66 .................................................................................. 124
Evaluate ....................................................................................... 125
67 .......................................................................................... 125
Intersect ............................................................... 126
t
e
n
.
p
68 .................................................................. 126
...................................................................................... 127
69 .................................................................. 128
Dictionary ............................................................................ 130
i
t
l
e
c
x
e
.
w
70 .................................................................................. 130
Sort .......................................................................................... 131
71 .............................................................................. 132
VBA .................................................. 133
72 .......................................................................................... 134
Locked ............................................................................ 135
73 .................................................................................................. 135
MID .................................................................................................. 137
74 VBA ........................................................................................ 137
.................................................................................................................. 138
75 ...................................................................................... 138
....................................................................... 140
76 5 .......................................................................... 141
Areas CurrentRegion ............................................................................... 142
77 1000 ............................................................................................ 142
.............................................................................................................. 143
78 .......................................................................... 144
Collection ............................................................................................. 145
79 VBA ............................................................................... 145
........................................................................... 146
80 ...................................................................... 147
VBA ........................................................................ 148
81 / ................................................................................. 149
/ .......................................................... 150
82 .................................................................................. 150
Replace ........................................................ 151
http://www.exceltip.net/forum-75-1.html
x XIX x
83
.................................................. 151
VBA ................................................................. 152
84
85
................................................................................. 154
...................................................................................... 156
86
87
......................................................................................... 156
......................................................................................... 159
88
...................................................................... 160
......................................................................... 161
89
t
e
n
.
p
i
t
l
e
c
x
e
.
w
3.3
90
......................................................................................... 165
91
92
.......................................................................... 168
.................................................. 168
93
...................................................................................... 171
............................................................................. 171
94
...................................................................................................... 172
.................................................. 172
95
.............................................................................................. 174
.................................................. 174
96
.......................................................................................................... 175
...................................................................... 175
97
.............................................................................................. 177
.................................................. 178
98
...................................................................................... 179
..................................................................................... 180
...................................................................... 181
.......................................................................................................................... 181
3.4
x XX x
99
................................................................................. 182
........................................... 183
100
............................................................................................... 184
............................................. 185
101
........................................ 186
http://www.exceltip.net/forum-75-1.html
..................................................................... 189
102 ............................................................ 189
......................................................................... 193
3.5
............................................................................................................. 199
105
t
e
n
.
p
i
t
l
e
c
x
e
.
w
3.6
................................................................ 212
Volatile .............................................................. 213
............................................................................................................................... 213
113
114
115
116
3.7
............................................................ 225
Excel 2003 ................................................. 226
118
................................................................................................ 227
Array ............................................................................. 228
http://www.exceltip.net/forum-75-1.html
x XXI x
119
3.8
4
4.1
........................................................ 229
VBA ...................................................... 230
................................................................................................................................... 231
.................................................................................................................................... 232
....................................................................................................................................... 232
120
............................................................ 232
............................................................................ 233
121
............................................................ 233
........................................................................ 234
122
................................................................................... 235
.................................................................... 235
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
4.2
...................................................................................................................... 236
123
........................................................................................... 237
............................................................................ 240
124
........................................................................................................... 240
............................................................ 243
4.3
5
5.1
x XXII x
126
....................................................................... 246
............................................................................ 253
127
........................................................................... 253
Export API .................................................... 255
128
................................................................ 256
HPageBreaks.Add ................................................................. 258
129
....................................................................................................... 259
............................................................................................ 260
130
........................................................................... 260
Location ............................. 261
................................................................................................................................... 262
.................................................................................................................................... 263
.......................................................................................................................... 263
131
................................................................................................... 263
Office ................................................................. 267
132
............................................................................................... 267
............................................................................................ 267
133
........................................................................... 269
http://www.exceltip.net/forum-75-1.html
..................................................................................... 271
.......................................................................................................................... 271
5.2
t
e
n
.
p
i
t
l
e
c
x
e
.
w
http://www.exceltip.net/forum-75-1.html
x XXIII x
153
..................................... 309
.................................................................... 310
154
.................................................................... 311
........................................................................... 312
155
......................................... 314
.................................................................... 314
............................................................................................ 316
...................................................................................................................... 316
5.3
t
e
n
.
p
156
....................................................................................... 316
MacroOptions ........................................................... 318
157
........................................................................... 318
REGISTER ........................................ 321
158
................................................ 322
159
i
t
l
e
6
c
x
e
.
w
5.4
.................................................................................................................................... 329
6.1
....................................................................................................................................... 329
160
........................................................................................... 329
SaveCopyAs ................................................................................. 330
161
........................................................................... 331
............................................................................................ 331
162
............................................................................... 332
GetAttr and .................................... 333
163
164
.................................................................... 334
18 ......................................................................... 335
165
166
................................................................................................ 338
........................................................ 338
167
........................................................................................ 339
Excel ................................................................................ 341
168
............................................................................ 342
.................................................................... 343
6.2
x XXIV x
http://www.exceltip.net/forum-75-1.html
6.3
7
7.1
t
e
n
.
p
................................................................................................................................... 351
.................................................................................................................................... 352
........................................................................................................................................ 352
i
t
l
e
c
x
e
.
w
7.2
........................................................................................................................................ 366
7.3
8
8.1
................................................................................................................................... 369
.................................................................................................................................... 370
.................................................................................................................. 370
http://www.exceltip.net/forum-75-1.html
x XXV x
............................................................................ 379
.......................................................................................................................... 379
8.2
184
........................................................ 379
AutoSize ................................................ 380
185
.................................................................... 381
3 ........................................................................ 383
186
........................................................ 383
........................................................................ 386
187
....................................................................... 386
.................................................................................... 388
188
............................................................................................... 388
Unload MeEndExit Sub .................................................... 391
189
........................................................................... 391
Isdate ......................................................... 392
190
........................................................................................... 392
................................................................................ 394
191
............................................................................... 394
................................................................................................ 395
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
8.3
...................................................................................................................... 396
192
....................................................................................... 396
DoEvents ...................................................................... 398
193
........................................................................... 398
.................................................................................... 401
194
............................................................................................... 402
3 ............................................................................ 404
8.4
196
197
.................................................... 408
API ........................................................................ 409
198
........................................................................... 410
API ........................................................................ 413
199
.................................................................... 413
FSO Getextensionname .................................... 417
................................................................................................................................... 417
.................................................................................................................................... 418
x XXVI x
http://www.exceltip.net/forum-75-1.html
9.2
............................................................................................................................... 426
203 ........................................................................ 426
KeyPress ......................................................... 428
t
e
n
.
p
i
t
l
e
c
x
e
.
w
............................................................................ 449
API ................................................................ 449
x XXVII x
http://www.exceltip.net/forum-75-1.html
219
9.3
................................................................................... 464
............................................................ 466
......................................................................................................... 467
220
............................................................ 467
ColumnHeads ................................................................... 469
221
............................................................................... 469
SetFocus .................................................................... 472
222
................................................................................................... 472
Excel ...................................................................................... 476
223
........................................................................................... 476
TextBox1_ChangeTextBox1_Exit............................. 478
224
................................................................................... 478
............................................................................................................ 481
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
225
.................................................................... 481
................................................................................................ 483
226
................................................................................... 484
............................................................................................ 485
............................................................................ 486
................................................................................... 486
227
9.4
228
............................................................................... 489
.................................................................................... 491
229
230
231
....................................................................................... 493
........................................................................... 495
232
233
............................................................................................ 499
............................................................ 500
9.5
10
.............................................................................................................................. 502
........................................................................... 502
.................................................................................... 506
x XXVIII x
http://www.exceltip.net/forum-75-1.html
t
e
n
.
p
i
t
l
e
c
x
e
.
w
11
...................................................................................................................... 564
http://www.exceltip.net/forum-75-1.html
x XXIX x
t
e
n
.
p
i
t
l
e
c
x
e
.
w
17179869184 234
30
2.1
Excel 2010 12
24
2-1
2-1
http://www.exceltip.net/forum-75-1.html
Find For...Next Loop
C
Range
1
Alt+F11 VBE
t
e
n
.
p
Sub ()
Dim rng As Range, RngTemp As Range, cell As Range '3Range
'C2CRng
Set rng = Range([c2], Cells(Rows.Count, "C").End(xlUp))
For Each cell In rng 'For...NextRng
If Len(cell) > 0 Then '0
If cell.Value < 60 Then '60
If RngTemp Is Nothing Then
'RngTemp
RngTemp
Set RngTemp = cell.Offset(0, -2)
Else
'RngTempRngTemp
Set RngTemp = Union(RngTemp, cell.Offset(0, -2))
End If
End If
End If
Next cell
'RngTemp
If RngTemp Is Nothing Then
MsgBox "", 64, ""
Else '
RngTemp.Interior.ColorIndex = 6
RngTemp.Select
End If
End Sub
i
t
l
e
c
x
e
.
w
w
3
2-2
2-2
http://www.exceltip.net/forum-75-1.html
45
VBA
C2 C
C
CellsRows.Count, "C" C Excel 2003
Excel 2010 Range("C65536")Range("C1048576")
t
e
n
.
p
EndxlUp C
Range("C2:C21")
i
t
l
e
c
x
e
.
w
w
Union
Union
Range
For Each...Next
For Each In
[Exit For]
Next []
Exit For
Sub 2()
Dim rng As Range, RngTemp As Range, i As Integer, j As Integer
Dim arr(), cell '
'C2CArr
arr = Range([c2], Cells(Rows.Count, "C").End(xlUp)).Value
i = 1 '1
For Each cell In arr 'For...Nextarr
i = i + 1 'i
If Len(cell) > 0 Then '0
If cell < 60 Then
j = j + 1 '60J
If j = 1 Then
'RngTempAiRngTemp
Set RngTemp = Cells(i, "A")
Else
46
http://www.exceltip.net/forum-75-1.html
2
'RngTempAiRngTemp
Set RngTemp = Union(RngTemp, Cells(i, "A"))
End If
End If
End If
Next cell
'J=0
If j = 0 Then MsgBox "", 64, "" Else
RngTemp.Interior.ColorIndex = 6: RngTemp.Select
End Sub
25
t
e
n
.
p
2-3
i
t
l
e
c
x
e
.
w
w
2-3
Alt+F11 VBE
http://www.exceltip.net/forum-75-1.html
47
VBA
If Not RngTemp Is Nothing Then 'RngTempNothing
firstAddress = RngTemp.Address '
Do '
'FindCell
If FindCell Is Nothing Then Set FindCell = RngTemp Else Set FindCell
= Union(FindCell, RngTemp)
Set RngTemp = rng.FindNext(RngTemp) '
Loop While RngTemp.Address <> firstAddress
End If
Next i
'FindCell
If Not FindCell Is Nothing Then FindCell.EntireRow.Select Else MsgBox"
": Exit Sub
On Error Resume Next '
ShtName = ActiveSheet.Name '
Set sht = Sheets("") 'sht
'
If Err.Number <> 0 Then '
Sheets.Add after:=Sheets(Sheets.Count) '
Sheets(Sheets.Count).Name = "" '
Else '
Sheets(Sheets.Count).Cells.Clear
End If
Sheets(ShtName).Select '
'
Selection.Copy Sheets(Sheets.Count).[a1]
End Sub
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
3
2-4
2-4
27 For...Next Find
For...Next Find FindCell
IF
Selection.Copy
Sheets("").[a1]
48
http://www.exceltip.net/forum-75-1.html
2
Copy
Activate PasteSpecial
Range.Find
.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase,
MatchByte, SearchFormat)
2-1
2-1 Range.Find
What
t
e
n
.
p
i
t
l
e
c
x
e
.
w
After
After
LookIn
xlCommentsxlFormulasxlValues
LookAt
SearchOrder
SearchDirection
MatchCase
True False
True
MatchByte
SearchFormat
False
Find Nothing
IF
Find
http://www.exceltip.net/forum-75-1.html
49
VBA
Operator:=xlFilterValues
On Error Resume Next '
ShtName = ActiveSheet.Name '
Set sht = Sheets("") 'sht
'
If Err.Number <> 0 Then '
Sheets.Add After:=Sheets(Sheets.Count) '
Sheets(Sheets.Count).Name = "" '
Else '
Sheets(Sheets.Count).Cells.Clear
End If
Sheets(ShtName).Select '
'
.SpecialCells(xlCellTypeVisible).Copy Sheets(Sheets.Count).[a1]
.AutoFilter '
End With
End Sub
t
e
n
.
p
i
t
l
e
c
x
e
.
w
Range("a1").CurrentRegion A1
Range(A1:D21)
Range.AutoFilter Field 3
SpecialCells(xlCellTypeVisible)
26
ListView
KeyUp
Find ListView
ListView
1
Alt+F11 VBE
UserForm1
2-5
50
http://www.exceltip.net/forum-75-1.html
2
5
F4
Caption:
6
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
2-5
2-6 ListView
ListView
ListView
9
'ListView1
Private Sub UserForm_Initialize()
With ListView1
.ColumnHeaders.Add , , "", 60 '60
.ColumnHeaders.Add , , "", 55 '55
.ColumnHeaders.Add , , "", 55 '55
.View = lvwReport
'ListView1
.Gridlines = True
'
End With
TextBox1.SetFocus '
End Sub
'
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Dim firstAddress As String, rng As Range '
ListView1.ListItems.Clear
'ListView
If TextBox1.Text = "" Then GoTo line 'Line
With Range("a:a")
'A
Set rng = .Find(TextBox1.Text, LookIn:=xlValues, Lookat:=xlPart)
If Not rng Is Nothing Then '
firstAddress = rng.Address '
Do '
Set Item = ListView1.ListItems.Add() 'ListView1
Item.Text = rng.Text
'
http://www.exceltip.net/forum-75-1.html
51
VBA
Item.SubItems(1) = rng.Offset(0, 1).Text '
Item.SubItems(2) = rng.Offset(0, 2).Text '
Set rng = .FindNext(rng) '
Loop While rng.Address <> firstAddress
End If
End With
line: '
'ListView1
ListView1.Height = ListView1.Font.Size * ListView1.ListItems.Count + 20
Me.Height = ListView1.Height + 70 'ListView1
End Sub
t
e
n
.
p
10
Sub ()
UserForm1.Show 0
End Sub
i
t
l
e
c
x
e
.
w
11
12
ListView
2-7
13
2-8
2-7
2-8
KeyUp
KeyUp SUB
ListView ListItems.Add()
SubItems(1)SubItems(2)
ListView ListView
20 ListView
52
http://www.exceltip.net/forum-75-1.html
2
12
Web Flash ImageList Dialog
Chart
UserForm1.Show 0
F5
10
27
t
e
n
.
p
? 2-9
Arial Black
i
t
l
e
c
x
e
.
w
w
2-9
Alt+F11 VBE
Sub ()
Dim FindStr As String, Rng As Range, mRng As Range
Application.FindFormat.Clear '
With Application.FindFormat '
.Font.Name = "Arial Black" '
.Font.Bold = True
'
.Interior.Color = 65535
'
End With
With Range("C:C") 'C
Set Rng = .Find(What:="", LookIn:=xlFormulas, LookAt:=xlPart,Search
Format:=True) '
If Rng Is Nothing Then MsgBox "": Exit Sub '
Set mRng = Rng '
FindStr = Rng.Address '
Do
Set mRng = Union(mRng, Rng)
http://www.exceltip.net/forum-75-1.html
53
VBA
'mrng
Set Rng = .Find(What:="", After:=Rng, SearchFormat:=True) '
'
Loop While FindStr <> Rng.Address
mRng.Select '
End With
End Sub
F5
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
2-10
FindFormat
FindFormat
2Application.FindFormat.Clear
2 2
Select
28
10 12
54
http://www.exceltip.net/forum-75-1.html
Excel FindFormat
ReplaceFormat Range.Replace SearchFormatReplaceFormat
Alt+F11 VBE
t
e
n
.
p
Sub ()
Application.FindFormat.Clear
'
Application.ReplaceFormat.Clear '
Application.FindFormat.Font.Size = 10
'10
Application.ReplaceFormat.Font.ColorIndex = 3
'
Application.ReplaceFormat.Font.Size = 12
'12
'
[c:c].Replace What:="", Replacement:="", LookAt:=xlPart,
SearchFormat:=True, ReplaceFormat:=True
End Sub
i
t
l
e
c
x
e
.
w
3 F5C 10
12 2-11
2-11 10 12
Application.FindFormat Application.ReplaceFormat
Range.Replace
SearchFormatReplaceFormat True
10
Sub 10()
Application.FindFormat.Clear
Application.ReplaceFormat.Clear
'
'
http://www.exceltip.net/forum-75-1.html
55
VBA
Application.FindFormat.Font.Size = 10
'10
'
[c:c].Replace What:="*", Replacement:="", LookAt:=xlPart,Search Format:=True
End Sub
29
2-12 ##
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
2-12
Range.Find ##
Superscript
#
Alt+F11 VBE
Sub ()
Dim rng As Range, i As Integer, First As String, inputt As String
inputt = InputBox("", "", "#")
'
Application.ScreenUpdating = False
'
Set rng = Cells.Find(inputt, LookAt:=xlPart, LookIn:=xlFormulas)
'
If Not rng Is Nothing Then
'
First = rng.Address
'
Do
'
For i = 1 To Len(rng) '
'
If Mid$(rng, i, 1) = Left(inputt, 1) Then rng.Characters(Start:=i,
Length:=1).Font.
Superscript = True
Next
Set rng = Cells.FindNext(rng) '
Loop Until rng.Address = First
End If
Application.ScreenUpdating = True '
End Sub
56
http://www.exceltip.net/forum-75-1.html
2
3
F5#
2-13
2-13 #
t
e
n
.
p
Range.Find LookAtxlPart#
i
t
l
e
c
x
e
.
w
Characters MID$
Superscript Subscript
M22
Sub M2()
Dim rng As Range, i As Integer, First As String, inputt As String
Application.ScreenUpdating = False
'
Set rng = Cells.Find("M2", LookAt:=xlPart, LookIn:=xlFormulas) '
If Not rng Is Nothing Then
'
First = rng.Address
'
Do
'
For i = 2 To Len(rng) '
'2M
If Mid$(rng, i, 1) = "2" And Mid$(rng, i - 1, 1) = "M" Thenrng.
Characters(Start:=i, Length:=1).Font.Superscript = True
Next
Set rng = Cells.FindNext(rng)
'
Loop Until rng.Address = First
End If
Application.ScreenUpdating = True
'
End Sub
30
2-14 C D
1
http://www.exceltip.net/forum-75-1.html
57
VBA
2-14
t
e
n
.
p
For...Next 1
i
t
l
e
c
x
e
.
w
Alt+F11 VBE
Sub () '
Dim rng As Range, cell As Range
For Each rng In Range([c2], Cells(Rows.Count, 3).End(xlUp))
'C
If Len(rng.Offset(0, 1)) > 0 Then 'D0
'12
If Evaluate("Datedif(" & rng.Address & ", " & rng.Offset(0, 1).Address
& ", ""M""" & ")") < 12 Then
'
If cell Is Nothing Then Set cell = rng Else Set cell =Application.
Union(cell, rng)
End If
End If
Next rng
'
If Not cell Is Nothing Then cell.EntireRow.Hidden = True
End Sub
F5 1
2-15
2-15
58
http://www.exceltip.net/forum-75-1.html
Datedif
12
Datedif
IF Len$
Datedif
Datedif
Datedif(start_date,end_date,unit)
t
e
n
.
p
i
t
l
e
c
x
e
.
w
VBA DateDiff
Datediff Datedif
1 Datediff Datedif 30
1 Datediff 1 Datedif 2 0
31
2-16
For...Next
SetText PutInCl1ipboard
1
Alt+F11 VBE
2-17 Microsoft
http://www.exceltip.net/forum-75-1.html
59
VBA
2-16
t
e
n
.
p
i
t
l
e
c
x
e
.
w
= i
= i
= i
Two
F5
F1 Ctrl+V F1:F3
VBA
DataObject
Office
Microsoft Forms 2.0 Object Library
DataObject M2.0.DLL
VBA Microsoft
Forms 2.0 Object Library
60
http://www.exceltip.net/forum-75-1.html
2-18
If MyData.GetFormat(1) Then MsgBox MyData.GetText(1)
2-18
t
e
n
.
p
Evaluate
Sub 2()
Set MyData = New DataObject 'DataObject
Dim str As String
str = Evaluate("=INDEX(A2:A37,MATCH(MAX(IF(B2:B37="""",C2:C37)),
IF(B2:B37="""",C2:C37),0))")
str = str & ": " & Evaluate("MAX(IF(B2:B37="""",C2:C37))")
str=str & Chr(10) & Evaluate("=INDEX(A2:A37,MATCH(MAX(IF(B2:B37=
"""",C2:C37)),IF(B2:B37="""",C2:C37),0))")
str = str & ": " & Evaluate("MAX(IF(B2:B37="""",C2:C37))")
str=str & Chr(10) & Evaluate("=INDEX(A2:A37,MATCH(MAX(IF(B2:B37=
"""",C2:C37)),IF(B2:B37="""",C2:C37),0))")
str = str & ": " & Evaluate("MAX(IF(B2:B37="""",C2:C37))")
MyData.SetText str
MyData.PutInClipboard
End Sub
i
t
l
e
c
x
e
.
w
32
CommandBars.Controls.Add
msoControlButton msoControlEdit msoControlEdit
OnAction msoControlEdit
Range.Find
Alt+F11 VBE
http://www.exceltip.net/forum-75-1.html
61
VBA
Sub auto_open() 'auto_open
On Error Resume Next '
CommandBars("Formatting").Controls("").Delete
'
CommandBars("Formatting").Controls("").Delete
'
With CommandBars("Formatting").Controls.Add(Type:=msoControlButton,
Temporary:=True)
.Caption = "" '
.BeginGroup = True '
.TooltipText = "" '
.Style = msoButtonCaption '
End With
'
With CommandBars("Formatting").Controls.Add(Type:=msoControlEdit,Temporary:
=True)
.Caption = "" '
.Text = ""
'
.OnAction = "intos" '
End With
End Sub
Sub intos()
With ActiveSheet.UsedRange '
Dim rng As Range, rngg As Range, firstAddress As String
Set rng = .Find(CommandBars("Formatting").Controls("").Text, LookIn:
=xlValues,lookat:=xlPart)
If Not rng Is Nothing Then '
firstAddress = rng.Address '
Do '
'Range
If rngg Is Nothing Then Set rngg = rng Else Set rngg = Union(rng,rngg)
Set rng = .FindNext(rng) '
Loop While rng.Address <> firstAddress
rngg.Select '
MsgBox "" & rngg.Address(0, 0) '
End
End If
MsgBox "" '
End With
End Sub
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
3
auto_openF5
2-21
62
http://www.exceltip.net/forum-75-1.html
2-19
2-21
t
e
n
.
p
CommandBars.Controls.Add OnAction
SUB
i
t
l
e
c
x
e
.
w
w
lookat
CommandBars("Formatting")
before:=1
Excel 2003 Excel 2010
Msgbox Application.StatusBar
33
2-22
Collection
For...Next
2-22
http://www.exceltip.net/forum-75-1.html
63
VBA
1
2
Alt+F11 VBE
Sub ()
On Error Resume Next 'Collection
Dim Only As New Collection, i As Integer, j As Integer
Dim arr, Arr2()
arr = Range([a1], Cells(Rows.Count, 3).End(xlUp)).Value
'
For i = UBound(arr) To 1 Step -1
'
'iCollection
Only.Add arr(i, 1), CStr(arr(i, 1))
If Err = 0 Then '(Collection)
j = j + 1 '
ReDim Preserve Arr2(1 To 3, 1 To j)
'
Arr2(1, j) = Only(j)
'Collectionarr2
Arr2(2, j) = arr(i, 2) 'arrj
Arr2(3, j) = arr(i, 3)
End If
Err.Clear '
Next i
[e1].Resize(j, 3) = WorksheetFunction.Transpose(Arr2)
'arr2
[g1].Resize(j, 1).NumberFormatLocal = "md" '
[h1].Resize(j, 1) = Evaluate("=row(1:" & j & ")")
'
',.
[e1].Resize(j, 4).Sort Key1:=[h1], Order1:=xlDescending,
OrderCustom:=1,
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
[h1].Resize(j, 1).Clear '
End Sub
t
e
n
.
p
i
t
l
e
c
x
e
.
w
3 F5 E G
2-23
2-23
Collection
64
http://www.exceltip.net/forum-75-1.html
2
Collection
VBA
Collection
Collection Collection
Dim X As New Collection
t
e
n
.
p
i
t
l
e
c
x
e
.
w
34
2-24 AB
Change
Alt+F11 VBE
2
2-25 Label5
2-24
2-25
'
http://www.exceltip.net/forum-75-1.html
65
VBA
Private Sub UserForm_Activate() '
For Each rng In [A2].Resize(ActiveSheet.UsedRange.Rows.Count - 1, 1)
If Len(rng) > 0 Then .AddItem rng.Text
'AA1
Next
= .List(0) '
End Sub
Private Sub _Change()
.Clear '
Dim i As Integer
'A
i = [a:a].Find(What:=.Text, After:=[a1], LookIn:=xlValues,
LookAt:=xlPart).Row
'ABA2:A5B2:B5
For Each rng In Cells(i, 2).Resize(Cells(i, 1).MergeArea.Rows.Count, 1)
If Len(rng) > 0 Then Me..AddItem rng.Text '
Next rng
=.List(0) '
End Sub
Private Sub _Change()
If Len() = 0 Then Exit Sub '
.Clear '
Dim i As Integer
'B
i = [B:B].Find(What:=.Text, After:=[B1], LookIn:=xlValues,
LookAt:=xlPart).Row
For Each rng In Cells(i, 3).Resize(Cells(i, 2).MergeArea.Rows.Count, 1)
If Len(rng) > 0 Then .AddItem rng.Text '
Next rng
= .List(0) '
End Sub
Private Sub _Change()
If Len() = 0 Then Exit Sub '
Dim i As Integer
'C
i = [C:c].Find(What:=.Text, After:=[C1], LookIn:=xlValues,
LookAt:=xlPart).Row
= Cells(i, 4) 'Di
End Sub
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
4
Sub ()
UserForm1.Show 0
End Sub
2-26
2-27
Change
66
http://www.exceltip.net/forum-75-1.html
2-26
2-27
MergeArea
t
e
n
.
p
MergeArea
i
t
l
e
c
x
e
.
w
Activate
Change
35
2-28
VBA ?
2-28
API ShellExecute For...Next
Alt+F11 VBE
http://www.exceltip.net/forum-75-1.html
67
VBA
Sub () '
Dim rng As Range, MyMail As String
For Each rng In Range([b2], Cells(Rows.Count, 2).End(xlUp))
MyMail = "mailto:" & rng.Offset(0, 1).Text & "?subject=&body=" &
rng.Offset(0, -1) & "%0A" & rng.Text & "%0A%0A" + Space(20)
& "" & Date
ShellExecute 0&, vbNullString, MyMail, vbNullString, vbNullString, 1
Next
End Sub
F5 2-29
t
e
n
.
p
i
t
l
e
c
x
e
.
w
w
2-29
ShellExecute Windows
VBA
68
http://www.exceltip.net/forum-75-1.html
2
MyMail = "mailto:" & Mid$(str, 1, Len(str) - 1) & "?subject=&body=
%0A" & Temp & "%0A%0A" + Space(20) & "" & Date
ShellExecute 0&, vbNullString, MyMail, vbNullString, vbNullString, 1
End Sub
2.2
VBA VBA
36
t
e
n
.
p
i
t
l
e
c
x
e
.
w
? 2-30
2-31
2-30
2-31
ShowPopup
ActionControl
SheetSelectionChange
CommandBars.Add
Alt+F11 VBE
Sub () '
Dim i As String, adds As String, sht As Worksheet
'
On Error Resume Next
Set sht = Sheets("")
If err.Number <> 0 Then MsgBox "
http://www.exceltip.net/forum-75-1.html
69
http://www.phei.com.cn/bookshop/bookinfo.asp?bookcode=TP120390&booktype=new
http://www.phei.com.cn/bookshop/bookinfo.asp?bookcode=TP120420&booktype=main
http://www.phei.com.cn/bookshop/bookinfo.asp?bookcode=TP120430&booktype=main