Proper Syntax for Range Item.Offset needed please

DougStroud

Well-known Member
Joined
Aug 16, 2005
Messages
2,976
Office Version
  1. 365
Platform
  1. MacOS
I am trying an alternative method to place a value in the last used row offset 2 columns.
The first statement here works:
Code:
Cells(Rows.Count, 1).End(xlUp).Offset(, 2).Value = "Last-Item"

But I am trying to use a variable to locate the last used cell in col. A then offset it by two columns and place the value in that cell, which currently is C93.
This one fails, LI finds the last used row fine, but then the Range method fails. I tried using Cells.(LI but that failed too.
Code:
LI = Cells(Rows.Count, 1).End(xlUp) '.Offset(, 2)
  Range(LI, 1).Offset(, 2).Value = "Last-Item
"

Thanks--

Doug
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Doug

You seem to be confusing useing "Range" and "Cells"

change 2nd line to

Cells(LI, 1).Offset(,2).Value = "Last-Item"

or either

Range("c" & LI).Value = "Last-Item"
Cells(LI, 3).Value = "Last-Item"
 
Upvote 0
Thanks Jindon,
I thought it was going to be Cells, but when that failed I was pondering that maybe ti was returning a range item....
But where my real problem was that I did not qualify an object, you used .Value, I omitted this.
What I was looking for was .Row- which is interesting because in this line
LI=cells(rows.count,1).end(xlup) returns a last used row value of 93
but
LI=cells(rows.count,1).end(xlup).row returns a last used row value of 104
104 is actually the correct value.
I cannot figure out why the first line returned a different value.
Is there a way to plug this into the Immediate Window to test like you showed me last night. "Sorry- not good w/ the debugging tools yet.. but trying"

thanks for all the contined help
 
Upvote 0
Doug

.Value is a default property of Rang/Cells, so if you omit property, it altomatically assumes as .Value.

If you see my codes, I never omit .Value, that's because I don't want to end up with unexpected result.
 
Upvote 0
J-
I did not omit it on purpose, but an error.
But you just taught me something interesting-
What ever value is placed in the last used range, and the object is omitted then the variable takes on that value.
That is why LI had a value of 93 when .Row was left off, because 93 is the last value in the last used cell in col. A
It was just a fluke that I had a numerical value there and that gave me a clue when you said that .value is the defalut of range/cells.
Had it been a text value I would not have discovered that.
ok.. again a late night so I am out of here.
I still want to go over your blazing fast loop, so maybe tomorrow night...

See you and thanks
 
Upvote 0

Forum statistics

Threads
1,222,174
Messages
6,164,391
Members
451,889
Latest member
invalidlabel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top