PDA

View Full Version : Solved: Increment offset



alstubna
05-23-2009, 09:41 AM
Greetings

I found some code on the net that does something I want.

It does a calculation and shows a message box with the result of that calculation. I would rather have the result entered into a cell. The cell that will get the result varies depending on what cell is the active cell when I run the code.

So far I have this -

ActiveCell.Offset(0, 1).Value = result

That works fine but sometimes I need to run the procedure several times and I need to save each result. So, what I need to do is increment the offset for each time I run the procedure. Something like this:

ActiveCell.Offset(0, find the next empty cell to the right of the active cell).Value = result

I'm sure this is simple but I'm not much of a coder.

georgiboy
05-23-2009, 10:11 AM
Its crude but if its only going to be run several times and not several thousand times in one sitting then you could try this...

Do While ActiveCell.Offset(, 1) <> ""
ActiveCell.Offset(1, 0).Activate
Loop

ActiveCell.Offset(0, 1).Value = "result"
Hope this helps

Bob Phillips
05-23-2009, 11:23 AM
Typo



Do While ActiveCell.Offset(0, 1) <> ""
ActiveCell.Offset(0, 1).Activate
Loop

ActiveCell.Offset(0, 1).Value = "result"


Another way



With ActiveCell

Cells(.Row, .Parent.Columns.Count).End(xlToLeft).Offset(0, 1).Value = "result"
End With

alstubna
05-23-2009, 11:48 AM
Thanks guys.

Went with xld's suggestion.

Works a treat!