简体   繁体   中英

How to assign cell value to a variable?

I'm trying to get some cell value and assign it to a variable.

Vars 'result' and 'result2' are two Long values that contains which row and column the value I'm looking for is. I've checked and the numbers match on the table but when I run the code it says

Error 1004 "Application-defined or Object-defined error".

Here's what I got:

For row = 1 To countRows
    brand = Sheets("2017").Cells(row, 1)
    If InStr(strSaida, brand) Then
        result2 = row
    End If
Next row

For col = 2 To countCol
    mes = Sheets("2017").Cells(2, col)
    If InStr(strProcMes, mes) Then
        result = col
    End If
Next col

Dim cellValor As Long
cellValor = Sheets("2017").Range(Cells(result2, result)).Value

This is the problem line

cellValor = Sheets("2017").Range(Cells(result2, result)).Value

It should be

cellValor = Sheets("2017").Cells(result2, result).Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM