How do I assign the value in a cell to a variable?

  • Thread starter Thread starter JasonK
  • Start date Start date
J

JasonK

I'm sure this is easy for someone, TIA.

I need a macro to search a range of cells (I can do that) and find a
cell with a value (which can change) verses other cells that have no
value. I can make the macro select the cell and copy it, but i need to
assign the value the macro finds in that cell to a variable. Does the
copied value in the clipboard have a name?

Thanks again,
Jason
 
You can create a variable in VBA and assign it the value of the cell
using the activeccell.value property

You can assign value when you track the cell with value

Your code could be
dim x 'declare a variable
x=activecell.value 'assing the variable the value of cell

For more,post your questions on
http://groups.google.co.in/group/answers-for-everything
 
You can create a variable in VBA and assign it the value of the cell
using the activeccell.value property

You can assign value when you track the cell with value

Your code could be
dim x 'declare a variable
x=activecell.value 'assing the variable the value of cell

For more,post your questions on
http://groups.google.co.in/group/answers-for-everything
 
You can create a variable in VBA and assign it the value of the cell
using the activeccell.value property

You can assign value when you track the cell with value

Your code could be
dim x 'declare a variable
x=activecell.value 'assing the variable the value of cell

For more,post your questions on
http://groups.google.co.in/group/answers-for-everything
 
You can create a variable in VBA and assign it the value of the cell
using the activeccell.value property

You can assign value when you track the cell with value

Your code could be
dim x 'declare a variable
x=activecell.value 'assing the variable the value of cell

For more,post your questions on
http://groups.google.co.in/group/answers-for-everything
 
That works if you know or have the active cell what you want. But lets say
you have six variables and you know of six different cells that have
information you want. Can you assign the values of those into the different
variables..

maybe something like

x = cell[a1].value
y=cell[b1].value
or something?
 
Dim Val01 as Variant
dim Val02 as Variant
Dim Val03 as Variant
dim Val04 as Variant
Dim Val05 as Variant
dim Val06 as Variant

with worksheets("whateverthenameishere")
val01 = .range("a1").value
val02 = .range("b99").value
val03 = .range("c23").value
val04 = .range("d13").value
val05 = .range("a11").value
val06 = .range("x9999").value
end with

=============
If you're setting this up and the users can insert/delete rows/columns, you may
want to use Insert|Name|Define to give each of those cells a nice name. Then if
they insert or delete rows or columns, the name will "move" with that cell--as
long as the user doesn't delete that cell.


with worksheets("whateverthenameishere")
val01 = .range("name01").value
val02 = .range("name02").value
val03 = .range("name03").value
val04 = .range("name04").value
val05 = .range("anothernamehere").value
val06 = .range("useanicenamehere").value
end with

I dimmed all the variables as variants, since I don't know if you have strings
or numbers in them.

Rookie_User said:
That works if you know or have the active cell what you want. But lets say
you have six variables and you know of six different cells that have
information you want. Can you assign the values of those into the different
variables..

maybe something like

x = cell[a1].value
y=cell[b1].value
or something?

Raman said:
You can create a variable in VBA and assign it the value of the cell
using the activeccell.value property

You can assign value when you track the cell with value

Your code could be
dim x 'declare a variable
x=activecell.value 'assing the variable the value of cell

For more,post your questions on
http://groups.google.co.in/group/answers-for-everything
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top