Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Place a word in a specific cell

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I have a spreadsheet that I calculate data every day on. I need the word current to be placed in a specific cell about 22 less than the last row. I have tried a couple of combinations of code that don't work. I was hoping for some help. Here is what I have:
Note: R5 is the calculation of the cell where I want the word to go.

Code:
R1 = ActiveSheet.UsedRange.Rows.Count
    R2 = "F" & R1
    'R3 = "A" & R1
    R4 = R1 - 17
    R5 = "I" & R4
    SR = R1 - 22
    ActiveWindow.ScrollRow = SR
    Range(R2).Select
    
    Worksheets("wbResults").Range("R5").Value = "Current"
 
How about something like (no need for the other variables unless something else needs them):
Code:
Worksheets("wbResults").Cells(ActiveSheet.UsedRange.Rows.Count - 22, 6) = "Current"
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 

Hi,

Assuming that the data in column R is contiguous and begins in R1...
Code:
[R1].end(xlDown).offset(-22).value = "Current"
or
Code:
with activesheet.usedrange
  .cells(.row+.rows.count-23,"R").value = "Current"
end with



Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
How on earth did I read that meaning the OP wanted it to go in column F? [ponder]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 



Harley,

Your solution assumes that the used range includes row 1, which may not necessarily be true.

And I should have included the Workbook and sheet objects [blush]

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I guess you wanted to replace this:
Worksheets("wbResults").Range("R5").Value = "Current"
with this ?
Worksheets("wbResults").Range(R5).Value = "Current"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I ran the following code:

Code:
Worksheets("wbResults").Cells(ActiveSheet.UsedRange.Rows.Count - 22, 6) = "Current"

I got a runtime error '9' Subscript out of range
 



maybe...
Code:
With Worksheets("wbResults")
  .Cells(.UsedRange.Rows.Count - 22, 6).value = "Current"
end with
[/code
This assumes that the usedrange begins in row .



Skip,
[sup][glasses]Don't let the [b]Diatribe[/b]...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
[b]for a NUANCE![/b][tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top