Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
Variable in Range VBA

Is it possible to use a variable in Range?

I have some cells called test1, test2, etc

Range("test1") works like Range("A1"), but Range(variable) or Range("variable") does not work.

I want to set a variable cellName and when I loop through test1, test2, the cells called test1, and test2, does something.

Dim cellName as String
Dim rng As Range, cell As Range

Set rng = Range("C5:C8")

For each cell In rng
  cellName = cell.Value
  Worksheets("Sheet2").Range("cellName").Value = "Good"
Next cell
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Try:

Sub test()
Dim cellName As String
Dim rng As Range

For Each rng In Range("C5:C8")
  cellName = rng.Value
  Worksheets("Hoja1").Range(cellName).Value = "Good"
Next rng

Set rng = Nothing


End Sub

enter image description here

enter image description here

about 4 years ago · Santiago Trujillo Denunciar

0

If you want to modify cells in C5:C8 you just need to do :

Dim cellName as String
Dim rng As Range, cell As Range

Set rng = Range("C5:C8")

For each cell In rng
  cell = "Good"
Next cell
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda