How To Get Cell Value By Row And Column In Excel VBA - ExcelDemy
Có thể bạn quan tâm
Get Cell Value by Row and Column in Excel VBA (Quick View)
Sub Cell_Value_from_Whole_Worksheet() Value = Worksheets("Sheet1").Cells(7, 3) MsgBox Value End SubHow to Get Cell Value by Row and Column in Excel VBA: 3 Methods
Method 1 – Get Cell Value by Row and Column from the Whole Worksheet in Excel VBA
To get the value from the cell in the 4th row and the 6th column of the worksheet called Sheet1, you can use:
Value = Worksheets("Sheet1").Cells(4, 6)⧭ Example:
We’ve got a worksheet called Sheet1 with the names of some students and their marks in Physics, Chemistry, and Mathematics of a School. The data set starts right from cell A1 of the worksheet.
To get the marks of the 6th student in Chemistry, you have to get the cell value from the 7th row and 3rd column of the worksheet.
⧭ VBA Code:
Sub Cell_Value_from_Whole_Worksheet() Value = Worksheets("Sheet1").Cells(7, 3) MsgBox Value End Sub
⧭ Output:
Run the code. It’ll display the cell value from the 7th row and 3rd column of Sheet1, which is 78.
Read More: Excel VBA: Get Cell Value from Another Workbook without Opening
Method 2 – Get Cell Value by Row and Column from the Used Range in Excel VBA
To get the value from the cell in the 4th row and the 6th column of the used range of the worksheet called Sheet2, you can use:
Value = Worksheets("Sheet2").UsedRange.Cells(4, 6)⧭ Example:
We’ve got another worksheet called Sheet2 with the same data set, the names of some students and their marks in Physics, Chemistry, and Mathematics of a School. This time the data set starts from cell B2 of the worksheet.
To get the marks of the 6th student in Chemistry again, you have to get the value from the 7th row and the 3rd column of the used range.
⧭ VBA Code:
Sub Cell_Value_from_Used_Ranget() Value = Worksheets("Sheet1").UsedRange.Cells(7, 3) MsgBox Value End Sub
⧭ Output:
Run the code. It’ll display the cell value from the 7th row and 3rd column of the used range of Sheet2, which is 78.
Method 3 – Get the Cell Value by Row and Column from a Specific Range in Excel VBA
To get the value from the cell in the 4th row and the 6th column of the range E2:H14of the worksheet called Sheet3, you can use:
Value = Worksheets("Sheet3").Range("E2:H14").Cells(4, 6)⧭ Example:
We’ve got another worksheet called Sheet3 with two data sets. One with the names and IDs of the students (B2:C14) of a School, and the other with the names of some students and their marks in Physics, Chemistry, and Mathematics (E2:H14).
To get the marks of the 6th student in Chemistry again, you have to get the value from the 7th row and the 3rd column of the range E2:H14 of the worksheet.
⧭ VBA Code:
Sub Cell_Value_from_Selected_Range() Value = Worksheets("Sheet3").Range("E2:H14").Cells(7, 3) MsgBox Value End Sub
⧭ Output:
Run the code. It’ll display the cell value from the 7th row and 3rd column of the range E3:G13 of Sheet3, which is 78.
Download the Practice Workbook
Get Cell Value by Row and Column.xlsmRelated Articles
- How to Get Cell Value as String Using Excel VBA
- Excel VBA Set Cell Value in Another Worksheet
Từ khóa » Visual Basic Excel Get Cell Value
-
VBA Cell Value - Get, Set, Or Change - Automate Excel
-
Get Cell Value In Excel VBA - WallStreetMojo
-
Excel VBA Get Cell Value - EduCBA
-
Range.Value Property (Excel) - Microsoft Docs
-
VBA Enter Value In A Cell (Set, Get, And Change) - Excel Champs
-
VBA Ranges - Getting And Setting Cell Values
-
How To Get Cell Value With VBA - Excel Tutorials - Officetuts
-
Get Cell Value - VBA / Excel / Access / Word
-
Getting Values From Another Sheet In Excel Using VBA - Chartio
-
How To Set Variable To Cell Value In Excel VBA? - GeeksforGeeks
-
Excel VBA Cell Value - Code Included - YouTube
-
Excel VBA Value And Value2: Step-by-Step Guide And 8 Examples
-
Cell Values And Displayed Text
-
Get Values From Other Sheet Using VBA - Stack Overflow