Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
#72836
O que estou tentando fazer é mais complexo, mas simplificando minha dúvida é:
quando executo este código, a variável "teste", que é do tipo range, mesmo com o loop alterando a váriavel "linha", a váriavel "teste" continua sendo a celula A1. O que devo fazer para que cada vez que a variável "linha" mudar seu valor, a variável "teste" também mude a célula?
Código: Selecionar todos
Sub teste()
    Dim teste As Range
    Dim linha As Integer
    
    linha = 1
    Set teste = Sheets(1).Range("A" & linha)
    
    Do Until linha = 5
        teste = "IMPRESSÃO" & linha
        linha = linha + 1
    Loop
End Sub
#72846
BrunoLuiel escreveu: 03 Fev 2023 às 16:32 ... mesmo com o loop alterando a váriavel "linha", a váriavel "teste" continua sendo a celula A1.
Após atribuir A1 à variável "teste", essa referência permanecerá na memória como teste= A1, independente da alteração no valor de "linha".

O que devo fazer para que cada vez que a variável "linha" mudar seu valor, a variável "teste" também mude a célula?
Basta mudar a atribuição para o Loop, conforme abaixo.
Código: Selecionar todos
   Do Until linha = 5
     Set teste = Sheets(1).Range("A" & linha)
     teste = "IMPRESSÃO" & linha
     linha = linha + 1
    Loop
JCabral, BrunoLuiel agradeceu por isso
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord