Reading an excel worksheet can be very complex when it involve a lot of data to read. You need to scroll to the left just to read the related information to the entity. This can be overcome or simplified by using VBA Userform. In this article, I will show you on how to get cell value in Excel VBA.
How To Get Cell Value In Excel VBA
Before you follow this guide, ensure that you already enable Developer mode and create userform in Excel.
Straight forward, you can use below code to get cell value in Excel. Replace “sheetname” with your excel Sheet’s name (eg; Sheet1, Sheet2 etc.) and replace “cellrange” with cell location (eg; A2, B2 etc.)
To give you a better view and understanding on how to use it, let me give you an example.
Let’s say we have Excel table with a person details like below:
And you want to populate the data in userform view as below:
Assume that you want to get the value for the first person (“Geek”), the cell range or location for the cell value will be like:
The VBA code will be like:
Click on play or execute button.
There, the information for “Geek” is shown on the userform.
If you want to read for the next person or user details, just change the range number for cell range to 3 as below:
It will show the details for “Harry”.
It’s very easy right.
You can put the action on button, like when you click the button, it will read the cell value.
Just add a button, let’s say name it “Read”. Then put action onClick, and put the code as below:
But in real situation, you should not edit the VBA code directly just to get the next value right? All you need is something that can get the next value, without need to change the code.
That means, you need a features to read the cell value dynamically. To proceed with dynamically get the cell value, you may refer this guide.
Thanks for reading this article. I hope you find it helpful.