Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda