Newbie - How to populate cells with new values using code?

D

deko

How to populate cells with new values using code?

I've done a fair bit of VBA programming in Access, but new to Excel VBA. I
can get into Design View and add a button to a Worksheet, and feel at home
in the VBA editor, but how do I read and write values to the worksheet? For
example, I want to read the value of each cell in a series of cells - say
A1:B40 - which are currently populated, and then process each value with an
algorithm that replaces the current value with a new value. I'll need to
loop through all the cells in the range, inspecting each one, so I figure an
array of some kind might work... I also want the new values to be inserted
on a different worksheet as well.

Can anyone help me get started?

Thanks in advance.
 
F

Frank Kabel

Hi
try something like the following

sub foo()
Dim rng as range
Dim cell as range
set rng = Activesheet.range("A1:B40")
for each cell in rng
if cell.value<>"" then
cell.value=cell.value*2
end if
next
end sub
 
Top