MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

how to get data into vba variable

  Asked By: Grant    Date: Sep 17    Category: MS Office    Views: 2730

Presently I am preparing a vba for converting figures to words. I am not
able to put figure from excel sheet to the variable in VBA.

Also I am not able to get the result variable back to excel sheet.

Please help me on it.

Also is it possible that I create a function (like Figure) for the above
so that I just put the function in the excel cell and the result just

e.g. Data cell A6 Contains 1000
I put the function in A7 as =FIGURE(A6) and result comes "Rs. One Thousand



2 Answers Found

Answer #1    Answered By: Abel Fischer     Answered On: Sep 17

I've copied below an exchange we had in the group a while back  that
should get you started on this custom function.

To pass a cell  value to VBA and back is quite straightforward, but made
immensely easier if you give the cell a range name first. For instance,
on a sheet  called Front sheet, the cell at A5 is given the range name
This_One. Its value can be passed to a VBA variable  valled varValue with
this line:

varValue=Sheets("Front sheet").Range("This_One").Value

You can write it back to the cell like this:

Sheets("Front sheet").Range("This_One").Value=varValue

Answer #2    Answered By: Julia Silva     Answered On: Sep 17

I've been meaning to find out if this worked. Have named
cells all along, but not since getting into VBA SUPER! Now I can
move things around and not have to parce my code for the references.

FYI, Abhishek,
You reference cells like this (absolute) too (some code snippets):

Get from the sheet  to VBA
f = ActiveSheet.Cells(Row, Col).value ' (.value is optional)
PortName = ActiveSheet.Cells(1, 12).Value

Going the other way
ActiveSheet.Cells(r, 2) = ModeName

Didn't find what you were looking for? Find more on how to get data into vba variable Or get search suggestion and latest updates.