-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCode
570 lines (328 loc) · 9.48 KB
/
TestCode
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
Sub SayHello()
MsgBox "hello"
End Sub
Sub lower()
Range("e3").Value = Range("e3").Value - 1
End Sub
Sub higher()
Range("e3").Value = Range("e3").Value + 1
End Sub
Sub findx()
If Range("e3").Value = "4" Then
Range("e3").Value = Range("e3").Value + 15
End If
End Sub
Sub findcellitem()
If cell.Item(3, 5) = 4 Then
cell.Item(3, 5) = 5
End If
End Sub
Sub findcellabc()
If Cells(3, 5).Value = 4 Then
Cells(3, 5).Value = 14 + 5
End If
End Sub
Sub SetCellValues()
Dim names As Range
Set names = Range("A2:A5")
Dim cell As Range
For Each cell In names
cell.Value = cell.Value & " " & cell.Offset(0, 1).Value
Next cell
End Sub
'Notes
'Range("B3").Value = 2
'Range("A1:A4").Value = 5
'Range("A1:A2,B3:C4").Value = 10
'Worksheets("Sheet1").Range("A1").Value = 3.14159
'Sheets(“sheet1”).range(“a3”).value = 1
'For Each c in Worksheets("Sheet1").Range("A1:D10")
' If c.Value < 0.001 Then
' c.Value = 0
' End If
'Next c
'Dim ws As Worksheet
'Set ws = Sheets(“sheet1”)
'ws.Range(“a4”).Value = 1
'Workbooks(“Book1.xlsm”).Sheets(“sheet1”).Range(“a3”).Value = 1
'ThisWorkbook.Sheets(“sheet1”).Range(“a3”).Value = 1
'Range for selecting cell in Excel Range declared
'For single Row Range("1:1")
'For single Column Range("A: A")
'For Contiguous Cells Range("A1:C5")
'For Non-Contiguous Cells Range("A1:C5, F1:F5")
'For Intersection of two ranges Range("A1:C5 F1:F5")
'(For intersection cell, remember there is no comma operator)
'To merge Cell Range("A1:C5")
'( To merge cell use "merge" command)
'Cells.item(1,1) OR
'Cells.item(1,"A")
Sub moveUp()
Selection.Offset(-1, 0).Select
End Sub
Sub moveDown()
Selection.Offset(1, 0).Select
End Sub
Sub moveRight()
Selection.Offset(0, 1).Select
End Sub
Sub moveLeft()
Selection.Offset(0, -1).Select
End Sub
Sub ListwithLoop()
Dim counter As Integer
For counter = 0 To 10
Selection.Value = counter
Selection.Offset(1, 0).Select
Next counter
End Sub
Sub finddatexyz()
Dim text
If Cells(1, 1).text = "11:11:11 AM" Then
MsgBox "asd1"
End If
If Cells(2, 1).Value = "7/12/2011" Then
MsgBox "asd2"
End If
'textx = Cells(3, 1).text
MsgBox Cells(1, 1).text
End Sub
Dim MyTime
MyTime = TimeValue("12:00:00 AM")
Dim MyTimeCurrent
MyTimeCurrent = Time
exactTime = FormatDateTime("12:00:00 AM", vbLongTime)
'exactTime = "00:00:00"
Sub ab()
Dim foundRng As Range
Set foundRng = Range("D3:D19").Find("Andrea")
If foundRng Is Nothing Then
MsgBox "Value not found"
Else
MsgBox foundRng.Address
End If
End Sub
Sub GetColumnsdawda()
Dim lnRow As Long, lnCol As Long
lnRow = 3 'For testing
lnCol = Sheet1.Cells(lnRow, 1).EntireRow.Find(What:="sds", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column
End Sub
Sub rangeasd()
Dim xxrow As Long
xxrow = Cells(1, Columns.Count).End(x1ToLeft).Column
MsgBox xxrow
End Sub
Sub rangefhdfhd()
row_number = 1
Do
DoEvents
row_number = row_number + 1
item_number = Sheet1.Range("A" & row_number)
If InStr(item_number, "5") > 0 Then
MsgBox row_number
End If
Loop Until row_number = 16
End Sub
Sub Range_End_Method()
'Finds the last non-blank cell in a single row or column
Dim lRow As Long
Dim lCol As Long
'Find the last non-blank cell in column A(1)
lRow = Cells(Rows.Count, 1).End(xlUp).Row
'Find the last non-blank cell in row 1
lCol = Cells(1, Columns.Count).End(xlToLeft).Column
MsgBox "Last Row: " & lRow & vbNewLine & _
"Last Column: " & lCol
End Sub
Sub Range_Find_Method()
'Finds the last non-blank cell on a sheet/range.
Dim lRow As Long
Dim lCol As Long
lRow = Cells.Find(What:="5", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
MsgBox "Last Row: " & lRow
End Sub
Sub GetColumnsasdsa()
Dim lnRow As Long
Dim lnCol As Long
lnRow = 1 'For testing
lnCol = Sheet1.Cells(lnRow, 1).EntireRow.Find(What:="5", LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column
MsgBox lnCol
End Sub
Sub program()
End Sub
' Find the name Jena in the range A1:A5
Dim rgFound As Range
Set rgFound = Range("1:1").Find("DATE")
' Print cell address to Immediate Window(Ctrl + G)
Debug.Print rgFound.Address
MsgBox rgFound.Address
'Function findFirstColumn(ByVal j As Integer) As Double
' Return 3.87 * j
'End Function
'End Sub
'Public Function FVax(PV As Variant, i As Variant, n As Variant) As Variant
'Public Function FVax(PV As Variant, i As Variant, n As Variant) As Variant
'Formula to calculate Future Value(FV)
'PV denotes Present Value
'FV = PV * (1 + i / 100) ^ n
'End Function
Private Sub compute_Click()
'This procedure will calculate Future Value
Dim FutureVal As Variant
Dim PresentVal As Variant
Dim interest As Variant
Dim period As Variant
PresentVal = PV.text
interest = Rate.text
period = years.text
FutureVal = FV(PresentVal, interest, period)
MsgBox ("The Future Value is " & FutureVal)
End Sub
Sub programadsadasd()
' Find the name Jena in the range A1:A5
Dim rgFound As Range
Set rgFound = Range("1:1").Find("DATE")
' Print cell address to Immediate Window(Ctrl + G)
Debug.Print rgFound.Address
MsgBox rgFound.Address
End Sub
Sub Test()
Dim RngToday As Range
Set RngToday = FindCurrentCell
If RngToday Is Nothing Then
MsgBox "Today's date not found"
Else
MsgBox "Today’s date in " & RngToday.Address
End If
End Sub
Public Function FindCurrentCell() As Range
Dim cell As Range
With Worksheets("Futures")
Set cell = .Cells.Find(What:=Date, After:=.Range("A1"), LookIn:=xlFormulas, _
SearchOrder:=xlByRows, SearchDirection:=xlNext)
If cell Is Nothing Then
' Today's date not found
' Add any appropriate code
Else
' Today's date found
' Add any appropriate code
End If
End With
Set FindCurrentCell = cell
End Function
Sub Tabellennamen_auslesen()
For i = 1 To Worksheets.Count
Sheets("Sayfa1").Cells(i, 1).Value = Sheets(i).Name
Next
End Sub
Sub Worksheet_Change(ByVal target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A1:C10")
If Not Application.Intersect(KeyCells, Range(target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
MsgBox "Cell " & target.Address & " has changed."
End If
End Sub
Private Sub Worksheet_Change(ByVal target As Range)
If target.Address = "$A$1" Then
Application.EnableEvents = False
'ENTER YOUR MACRO HERE THAT WILL RUN WHEN CELL CHANGES
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_Change(ByVal target As Range)
MsgBox target.Address
End Sub
Private Sub Worksheet_Change(ByVal target As Range)
Dim KeyCells As Range
Set KeyCells = Range("A1:C10")
If Not Application.Intersect(KeyCells, Range(target.Address)) Is Nothing Then
Call Sample
MsgBox target.Address
End If
End Sub
Sub Sample()
MsgBox "yes"
End Sub
Option Explicit
Public Sub Worksheet_Change(ByVal target As Range)
Dim intersection As Range
Set intersection = Intersect(target, Range("A1:B3"))
If Not intersection Is Nothing Then
MsgBox target.Address(0, 0)
MsgBox intersection.Address(0, 0)
End If
End Sub
Sub findHourCell()
Dim RowHour As Integer
Dim LastColumn As Integer
Dim LastRow As Integer
Dim counter As Integer
Dim columnHour As Integer
For counter = 1 To 50
If Cells(1, counter).Value = "HOUR" Then
columnHour = counter
End If
Next counter
For counter = 1 To 500
If Cells(1, counter).Value = "" Then
LastColumn = counter
End If
Next counter
For counter = 1 To 35
If Cells(counter, columnHour).Text = "00:00:00" Then
RowHour = counter
LastRow = counter + 23
End If
Next counter
MsgBox RowHour
MsgBox columnHour
MsgBox LastRow
End Sub
Private Sub Worksheet_Change(ByVal target As Range)
Dim KeyCells As Range
Set KeyCells = Range(Cells(1, 1), Cells(1, 10))
'Set KeyCells = Range("A1:A10")
Dim exact_Cell As Range
Dim rowabc As Integer
If Not Application.Intersect(KeyCells, target) Is Nothing Then
rowabc = target.Row
Call Import2PIAuto(rowabc)
'MsgBox target.Column
End If
End Sub
Sub Import2PIAuto(ByVal rowxyz As Integer)
'MsgBox rowxyz
MsgBox "yes"
End Sub
Sub abc123()
Range(Cells(6, 1), Cells(6, 3)).Value = 5
End Sub
Sub RangeTest()
Dim testRange As Range
Dim targetWorksheet As Worksheet
Set targetWorksheet = Worksheets("MySheetName")
With targetWorksheet
'.Cells(5, 10).Select 'selects cell J5 on targetWorksheet
Set testRange = .Range(.Cells(1, 1), .Cells(1, 10))
End With
testRange.Select 'selects range of cells E5:J10 on targetWorksheet
MsgBox testRange
End Sub
Sub GetColumn51()
Dim ws As Worksheet
'ActiveSheet.Range("A5").Value = 1
ActiveSheet.Cells.Item(1, 1).Value = 1
Range(Cells(6, 1), Cells(10, 3)).Value = 5
End Sub