VBA Save cell value in a variable

Опубликовано: 16 Март 2026
на канале: Kevin Brundu
7,218
18

Save the cell value in a variable to re-use it later in your macro.

Code:

Sub save_cell_value_in_variable()

'how to read/save the value of a cell in a variable

Dim ws_sheet As Worksheet
Dim cell_value As Variant

'identify the worksheet
Set ws_sheet = Worksheets(1)

'find the cell value from the range name , A1 in this example
cell_value = ws_sheet.Range("A1").Value

'display the value in a message box
MsgBox ("Test 1 : " & cell_value)

'find the cell value with Row/Column properties, row 1 and column 1 in this example (which is also A1)
cell_value = ws_sheet.Cells(2, 1).Value

'display the value in a message box
MsgBox ("Test 2 : " & cell_value)

'find the cell value with Row/Column properties and column name, here, row 1 and column A
cell_value = ws_sheet.Cells(1, "B").Value

'display the value in a message box
MsgBox ("Test 3 : " & cell_value)

End Sub

-------------------------------
THANK YOU
-------------------------------
For watching my videos,
Your shares
And your comments!

-------------------------------
CONTACT ME
-------------------------------
Send your messages (questions, training requests or creation of files): https://www.kevinbrundu.com/contact/
Stay informed: https://kevinbrundu.com/en/homepage

-------------------------------
ONLINE COURSES
-------------------------------
Find all the news and links of my online courses on my website https://kevinbrundu.com/en/homepage

-------------------------------
SOCIAL NETWORKS
-------------------------------
Website: https://kevinbrundu.com/en/homepage
LinkedIn:   / k%c3%a9vin-brundu-9a910241  
Facebook:   / kevinbrunduauteur  

-------------------------------
MERCI
-------------------------------
De regarder mes vidéos,
Pour vos partages
Et vos commentaires !

-------------------------------
RENDEZ-VOUS SUR MON SITE INTERNET
-------------------------------
https://www.kevinbrundu.fr/

Retrouvez y :
Des fichiers Excel à télécharger gratuitement
Mes formules clés en main sur Excel avec des fichiers prêts à l'emploi
Mes services de Consultant Optimisation, Performance et Génération d'idées

-------------------------------
AUTRES RESSOURCES EN LIGNE
-------------------------------
Livres publiés : https://www.amazon.fr/Kévin-Brundu/e/...
Cours en ligne sur Udemy :
VBA Macro Excel - Formulaire simplifié sur une feuille Excel https://www.udemy.com/course/macro-ex...

VBA Macro Excel - Compiler des fichiers dans un seul tableau https://www.udemy.com/course/macro-ex...

Suivez toutes les actualités sur mon site internet directement.

-------------------------------
DES QUESTIONS ?
-------------------------------
Laissez vos questions en commentaires ou contactez-moi directement via mes réseaux sociaux.

-------------------------------
RESEAUX SOCIAUX
-------------------------------
Pour en savoir plus sur moi et me contacter :
Site internet : https://www.kevinbrundu.fr/
LinkedIn :   / k%c3%a9vin-brundu-9a910241