thorpedosg

eg8XVJDy

Aug 6th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. Collection won't store string
  2. Sub TestCollection()
  3.  
  4. Dim i As Single, col As New Collection
  5. Dim vArr(1 To 3) As String
  6.  
  7. 'For i = LBound(vArr) To UBound(vArr)
  8. ' vArr(i) = Sheets("Sheet2").Cells(1, i)
  9. 'Next i
  10.  
  11. vArr(1) = "String 1"
  12. vArr(2) = "String 2"
  13. vArr(3) = "String 3"
  14.  
  15. For i = LBound(vArr) To UBound(vArr)
  16. Debug.Print vArr(i)
  17. col.Add i, vArr(i)
  18. Debug.Print col(i)
  19. Next i
  20.  
  21. End Sub
  22.  
  23. Item 1 -> "String 1"
  24. Item 2 -> "String 2"
  25. Item 3 -> "String 3"
  26.  
  27. Item 1 -> 1
  28. Item 2 -> 2
  29. Item 3 -> 3
  30.  
  31. vArr(1) = "String 1"
  32. vArr(2) = "String 2"
  33. vArr(3) = "String 3"
  34.  
  35. For i = LBound(vArr) To UBound(vArr)
  36. col.Add vArr(i), CStr(i)
  37. Sheet1.Cells(1, i) = col.Item(i)
  38. Next i
  39.  
  40. vArr(1) = "String 1"
  41. vArr(2) = "String 2"
  42. vArr(3) = "String 3"
  43.  
  44. For i = LBound(vArr) To UBound(vArr)
  45. col.Add vArr(i)
  46. Sheet1.Cells(1, i) = col.Item(i)
  47. Next i
  48.  
  49. Dim i As Single, col As New Collection
  50. Dim vArr(1 To 3) As String
  51.  
  52. vArr(1) = "Column 1"
  53. vArr(2) = "Column 2"
  54. vArr(3) = "Column 3"
  55.  
  56. For i = LBound(vArr) To UBound(vArr)
  57. col.Add i, vArr(i)
  58. Next i
  59.  
  60. For i = LBound(vArr) To UBound(vArr)
  61. Dim columnNumber As Integer
  62. columnNumber = col("Column 2")
  63. Sheet1.Cells(1, columnNumber).Value = "Found it"
  64. Next i
  65.  
  66. col.Add vArr(i), CStr(vArr(i))
  67.  
  68. col.Add vArr(i), CStr(i)
Add Comment
Please, Sign In to add comment