VBA-Excel: Range of a cell contained in a variable

Asked

Viewed 238 times

1

I need to take the contents of cells identified in a variable. It is possible?

Code:

VTI40 = "J44"
VTF40 = "J47"
VTI39 = "H44"
VTF39 = "H47"

QtdVal = Range("B60").Value

QtdInv = 40 - QtdVal

For i = 40 To QtdInv Step -1
    VTI = "VTI" & i
    VTF = "VTF" & i
    CelI = Range(VTI).Value   -> Aqui o conteúdo da célula "J44"
    CelF = Range(VTF).Value   -> Aqui o conteúdo da célula "J47"
Next i
  • I suggest using .Cells() in this loop and not Range. But do a [mcve] with the table data as it is difficult to visualize this way. Create in example with fictitious data.

  • 1

    Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of it. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English (short version). If the solution is very simple it is still possible for someone to do so in the comments.

1 answer

0

Want to copy the values of certain cells and put in a single variable.

valor = ThisWorkbook.Worksheets("Folha9").Range("A" & 20, "E" & 20)

In this example we take the values from A 20 to E 20. The variable "value" will consist of 5 values (which is found in A20, B20 to E20). You would need to cycle to put these values into a string.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.