Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is worksheet.Cells(row,col).Formula

I was watching a tutorial for comparing two excel worksheets and came across this:

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

In the video he says that this assigns the value of the specified cell to the cellVal1. I've only seen people use ws.Cells(row, col).Value and can't seem to find anything about .Formula with regards to .Cells(<row>,<col>)

What does .Formula do and is it different than .Value?

like image 743
Justin L. Avatar asked Jan 06 '16 20:01

Justin L.


People also ask

What is worksheet and column row and cell?

Every worksheet is made up of thousands of rectangles, which are called cells. A cell is the intersection of a row and a column—in other words, where a row and column meet. Columns are identified by letters (A, B, C), while rows are identified by numbers (1, 2, 3).

What is worksheet cells?

A worksheet (also known as a spreadsheet) consists of cells in which you can enter and calculate data. The cells are organized into columns and rows. A worksheet is always stored in a workbook. A workbook can contain many worksheeks.

What is worksheet column?

A column is a vertical series of cells in a chart, table, or spreadsheet. Below is an example of a Microsoft Excel spreadsheet with column headers (column letter) A, B, C, D, E, F, G, and H. As you can see in the image, the last column H is the highlighted column in red and the selected cell D8 is in the D column.

What is a row in worksheet?

What is a row in Excel? Each row is denoted and identified by a unique numeric value that you'll see on the left hand side. The row numbers are arranged vertically on the worksheet, ranging from 1-1,048,576 (you can have a total of 1,048,576 rows in Excel). The rows themselves run horizontally on a worksheet.


1 Answers

The .formula part takes the formula inside the cell and .value only take the value 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 (that is equal to Range("A3").formula) you get =A1+A2, but if you use .value you got 6. Remember if you try to store a string inside a int type varible, you get an error, because the formula is a string.

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

like image 124
Elbert Villarreal Avatar answered Sep 24 '22 08:09

Elbert Villarreal