Pregunta

Tengo 264 columnas de datos que necesito para establecer cada uno indiviente como un rango para almacenar el valor en una variable ... así que estoy pensando como:

For i = 1 To 5

If i = 1 Then
    search1 = Sheets(tables).Range(Cells(2, i), Cells(200, i))
ElseIf i = 2 Then
    search2 = Sheets(tables).Range(Cells(2, i), Cells(200, i))
ElseIf i = 3 Then
    search3 = Sheets(tables).Range(Cells(2, i), Cells(200, i))
ElseIf i = 4 Then
    search4 = Sheets(tables).Range(Cells(2, i), Cells(200, i))
ElseIf i = 5 Then
    search5 = Sheets(tables).Range(Cells(2, i), Cells(200, i))
End if

Next

(Tengo 264 años, así que creo que no es bueno hacer eso ...) Cómo puedo hacer esto ?

He intentado:

search & i = Sheets(tables).Range(Cells(2, i), Cells(200, i))
"Compiler error, expected expression"
search(i) = Sheets(tables).Range(Cells(2,i),Cells(200,i))
"Sub or Function not Defined"

y todavía no trabajes.

es lo posible?¿Tienes algún consejo?trucos para hacer esto?

Por favor, dígame cualquier pensamiento, le daré la mayor cantidad de información posible para tener al menos una excelente solución aquí.

gracias.

¿Fue útil?

Solución

Pruebe este código:

Sub test()
    Dim i As Integer, n As Integer
    Dim tables As String
    Dim search() As Variant

    n = 264
    ReDim search(1 To n)

    tables = "Sheet1"

    With ThisWorkbook.Sheets(tables)
        For i = 1 To n
            search(i) = .Range(.Cells(2, i), .Cells(200, i)).Value
        Next
    End With

End Sub

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top