macro_bucle_mayusculas.bas

  1. 'Attribute VB_Name = "MacroBucleMayusculas"
  2. Option Explicit
  3.  
  4. Sub MacroBucleEnLaSeleccion()
  5.  
  6. 'Variable rango
  7. Dim rango As Range
  8. Dim celda As Range
  9.  
  10. 'El rango es la selección actual
  11. Set rango = Selection
  12.  
  13. 'Mostrar la dirección del rango
  14. MsgBox rango.Address
  15.  
  16. 'Para cada celda en el rango
  17. For Each celda In rango.Cells
  18.  
  19. 'Mostrar la dirección de la celda
  20. MsgBox celda.Address
  21.  
  22. Next
  23.  
  24. End Sub
  25.  
  26. Sub MacroMayusculas()
  27.  
  28. Dim rango As Range
  29. Dim celda As Range
  30.  
  31. Set rango = Selection
  32.  
  33. For Each celda In rango.Cells
  34.  
  35. 'Toma el valor de la celda, pasarlo a mayúsculas y
  36. 'actualizar el valor de la celda
  37. celda.Value = UCase(celda.Value)
  38.  
  39. Next
  40.  
  41. End Sub
  42.  
  43. Sub MacroMinusculas()
  44.  
  45. Dim rango As Range
  46. Dim celda As Range
  47.  
  48. Set rango = Selection
  49.  
  50. For Each celda In rango.Cells
  51. celda.Value = LCase(celda.Value)
  52. Next
  53.  
  54. End Sub
  55.  
  56. Sub MacroNombrePropio()
  57.  
  58. Dim rango As Range
  59. Dim celda As Range
  60.  
  61. Set rango = Selection
  62.  
  63. For Each celda In rango.Cells
  64. celda.Value = WorksheetFunction.Proper(celda.Value)
  65. Next
  66.  
  67. End Sub
  68.  
  69. Sub MacroPrimeraMayusculas()
  70.  
  71. Dim rango As Range
  72. Dim celda As Range
  73.  
  74. Set rango = Selection
  75.  
  76. For Each celda In rango.Cells
  77. celda.Value = PrimeraMayusculas(celda.Value)
  78. Next
  79.  
  80. End Sub
  81.  
  82. Function PrimeraMayusculas(texto As String) As String
  83. PrimeraMayusculas = UCase(Left(texto, 1)) & LCase(Mid(texto, 2))
  84. End Function
  85.  

Proinf.net