ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   setting cell values in another worksheet? (https://www.excelbanter.com/excel-programming/412381-setting-cell-values-another-worksheet.html)

al

setting cell values in another worksheet?
 
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!


Gary Keramidas

setting cell values in another worksheet?
 
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

--


Gary


"Al" wrote in message
...
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!





All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com