What is a worksheet? Colors (row, column).

I looked at a tutorial for comparing two Excel spreadsheets and came across this:

cellVal1 = ws1.Cells(row, col).Formula 

In the video, he says that it assigns the value of the specified cell to cellVal1 . I only saw that people use ws.Cells(row, col).Value and cannot find anything about .Formula regarding .Cells(<row>,<col>)

What does .Formula and is different from .Value ?

+5
source share
1 answer

The .formula part takes the formula inside the cell, and the .value takes only the value that you can see.

enter image description here

 A1 = 2 A2 = 4 A3 = 6 

In A3 there is a formula =A1+A2 , if you use .formula to put the formula inside cellVal1 using cellVal1 = Cells(3, 1).Formula (i.e. Range("A3").formula ), you get =A1+A2 , but if you use .value , you got 6 . Remember, if you try to save a string inside an int variable, you will get an error because the formula is a string.

TIP: if you use .formulaR1C1 , you will get =R[-2]C+R[-1]C

+4
source

Source: https://habr.com/ru/post/1240026/


All Articles