Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub test()
  2.     Dim Arr() As Range
  3.     Arr = Range("A1:A10")
  4.    
  5.     Dim counter As Integer
  6.     For counter = LBound(Arr) To UBound(Arr)
  7.         Arr.Cells MsgBox(Arr.Cells().Cells(counter, 1).Value)
  8.         'If Arr(counter) > Arr(counter + 1) Then
  9.        '    MsgBox (counter)
  10.        'End If
  11.    Next counter
  12.     MsgBox ("Hello, world!")
  13. End Sub
  14. Sub Program()
  15.  
  16. Dim rangeValues() As Variant
  17. Dim x As Long
  18. Dim counter As Integer
  19.  
  20. 'Resize Array prior to size of Selected Range
  21. ReDim rangeValues(Selection.Cells.Count)
  22.  
  23. 'Loop through each cell in Selected Range and store value in Array
  24. For Each cell In Selection
  25.     rangeValues(x) = cell.Value
  26.     x = x + 1
  27. Next cell
  28.  
  29. 'Do work
  30. counter = 0
  31. Debug.Print ("Positions of elements matching the required condition")
  32. For i = LBound(rangeValues) To UBound(rangeValues) - 2
  33.     If rangeValues(i) > rangeValues(i + 1) Then
  34.         Debug.Print (i + 1)
  35.         counter = counter + 1
  36.     End If
  37. Next i
  38. Debug.Print ("Amount of the elements " & counter)
  39.  
  40. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement