The value of a cell in a VBA variable

Solved
Grobibi34 Posted messages 83 Status Membre -  
 bob26 -
Hello everyone. Well, I have a big problem in Excel and I think it's a bit complicated to explain.
So I would like to go step by step.

First of all, how can I place the value of a cell in a VBA variable?

It may seem like a silly problem, but I'm a bit stuck on this silliness.

Best regards

Grobibi34
Configuration: Windows XP Internet Explorer 6.0

3 réponses

Ivan-hoe Posted messages 433 Registration date   Status Membre Last intervention   309
 
Hi Grobibi,
1°) declare your variable:
Dim NomVariable

2°) assign it the value of a cell:
NomVariable = range("A1").Value

If necessary, refer to the workbook and the sheet:
NomVariable = Workbooks("NomClasseur").Sheets("NomFeuille").Range("A1").Value


Keep up the good work!
124
Grobibi34 Posted messages 83 Status Membre 30
 
Suuuuuper, it works perfectly, thank you very much Ivan-hoe ;-)
26
Ménilmuche Posted messages 19 Registration date   Status Membre Last intervention  
 
Hello,

I'm looking for a way to do the opposite, that is to say, to copy the value of a variable into a cell of a workbook.

Actually, I created a form template to generate invoices. I need the invoice number to increment by 1 for each new invoice.

I'm struggling to do this. I managed to make it work when opening the template by creating an Auto_Open procedure, but it doesn't work when creating a new document from this template.

I'm sure it's possible to do it using a variable that keeps the values and which would be written each time an invoice is created, but I haven't found it.

Could you help me?
0