Simple VBA question

B

bretthotep

Hi everybody,

I have a problem,
I have written some code where I am trying to access a row and the
individual cells within that row

sub cellTest()

dim cellRng as Range
dim wrkSht as Worksheet
dim cellVal as variant

set cellRng = Worksheets("Sheet 1").Rows(1)
'this function runs and should return a range of cells from row 1 in
Sheet 1 however does not.

'get the first cell in the range
set cellVal = cellRng(1)

'output the value
Msgbox "value is " & cellVal.Value "."

end sub

Can somebody help me, can I use a range like this or do I have to run a
loop picking out all the cells individually from the row.

Thanks,
 
T

TC

You don't say why it doesn't work. Do you get an error? If so, what?

I don't have Excl handy to chek, but I doubt that cellRng(1) would
return the first cell in the range 'cellRng'. You'd need
cell.Rng.Cells(1), so somesuch.

HTH,
TC
 
B

bretthotep

Actually I tried that but it doesnt seem to work.
I receive no error message, I tried tracing it and it seems that
something goes into cellRng just not what I want to go in there.
I tried using cellRng.Cells(1) however it wont output a value.
Activecell = cellRng.Cells(1)
 

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

Top