setting cell values in another worksheet?

A

Al

I am setting values in one worksheet while reading another worksheet. How do
I reference the cell in the worksheet I am writing to? I would rather use
cell references then I can do cell calculations
(Worksheets("Table").Cells(c+3,sr))

The following all causes errors:

Worksheets("Data").Select
sr = 4
colcount = 7
Worksheets("Table").Range("A" & sr).Value = Cells(r, 1)
Worksheets("Table").Range("B" & sr).Value = Hour(Cells(r, 2))
Worksheets("Table").Range((colcount + 3) & sr).Value =
Worksheets("Table").Range((colcount + 3) & sr) + 1

Thanks for you help!
 
G

Gary Keramidas

i'll take a stab but i'm not real sure what you want. i added a variable, r,
because i didn't mention what it was. always preferable to dim your variables.

Sub test()
Dim r As Long
Dim sr As Long
Dim colcount As Long

Worksheets("Data").Select
r = 2
sr = 4
colcount = 7
Worksheets("Table").Range("A" & sr).Value = Cells(r, 1)
Worksheets("Table").Range("B" & sr).Value = Hour(Cells(r, 2))
Worksheets("Table").Cells((colcount + 3), sr).Value = _
Worksheets("Table").Cells((colcount + 3), sr).Value + 1

End Sub
 

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