I have a For
loop which will find a cell with a certain value in it (e.g. the word "Item"). Once it finds this cell, I want to paste a value into the row below it, in column I.
For example, if the For
loop finds "Item" in cell A1, I want to paste the value of a variable into cell I2.
I'd like to be able to do this with both a Long
variable and a String
variable.
Right now I'm trying something like:
Cells(i.Offset(1, 0), 9).Value = myLongVariable
or
Cells(i.Offset(1, 0), 9).Text = myStringVariable
and other variations, but I keep getting an overflow error at this line.
I've tried this: Range("I" & i.Offset(1, 0)).Value = myLongVariable
and slight variations, but I get an error that says Run-time error 1004: Method Range of object _Worksheet failed
Or workBook.Sheets("Sheet1").Range("I" & i.Offset(1, 0)).Value = myLongVariable
but that gives Run-time error 1004: Application-defined or object-defined error
. Not sure what that refers to since I've defined workBook
and i
and myLongVariable
.
As a slightly different approach, I've tried pasting the variable data into the next blank cell of the row, which happens to be the cell in column I. Here's the code I used for that: 'i.Offset(1, 0).End(xlToRight).Offset(0, 1).Value = myLongVariable
. It works great, except in this scenario: cells A1:C1 are blank, D1:H1 have values. It should then paste the value into I1, but instead it thinks D1 is the end and posts it there. Any ideas on that?
Thanks!