To read cell values in Excel VBA, you can use the Range object. The Range object represents a cell or a range of cells in Excel. Here’s an example of how you can read a cell value using VBA:
' Define a variable to store the cell value
Dim cellValue As Variant
' Specify the cell you want to read
Dim cell As Range
Set cell = Worksheets("Sheet1").Range("A1")
' Read the cell value
cellValue = cell.Value
' Display the cell value in a message box
MsgBox cellValue
In the above example, we first declare a variable cellValue
to store the value of the cell. Then we specify the cell we want to read using the Range
object. In this case, we are reading cell A1
in Sheet1
.
After that, we use the .Value
property of the Range
object to get the value of the cell and assign it to the cellValue
variable. Finally, we display the cell value in a message box using the MsgBox
function.