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!

adding cells

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
bascially i want to take the value of the activecell and add it with the value of the cell that is 3 rows above, but i want to put the answer in that same cell, i tried this code but it didnt work

ActiveCell.Value = ActiveCell.Value + ActiveCell.Offset(-3, 0).Range("A1").Select

I dont see why that woudlnt work, but anyone have any ideas, thanks!
 
As you should have seen when you ran the macro, using .Select changed the active cell. This is more like what you want:
Code:
ActiveCell.Value = ActiveCell.Value + ActiveCell.Offset(-3, 0).Value
 
4335 - you must REALLY learn not to use that select. That's the 2nd time you've posted and the select has been a problem

To put a value in a cell, you use

Range("Cell_Ref").value = SomeValue

There is no select necessary. In fact SELECT is very very rarely needed at all........for anything Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
just to follow up, can i use any function within a cell, if that function refers to a cell, for example, if i want to see whether the activecell is exact to the cell 3 rows above, i tried

ActiveCell.FormulaR1C1 = "=exact(activecell.value, activecell.offset(-3, 0).value)"

and i get an error, i tried

ActiveCell.FormulaR1C1 = "=exact(activecell, activecell.offset(-3, 0))"

and it doesnt recognize that i want whats in the activecell, not the actual word activecell or activecell.offset

is it possible to do what i want, thanks!
 
Try putting
Code:
  MsgBox ActiveCell.FormulaR1C1
and see to what extent it is equal to
Code:
  "=exact(activecell, activecell.offset(-3, 0))"
I find that frequent use of MsgBox helps me a great deal when I am writing macros.

To answer your question try
Code:
  if ActiveCell.Value = ActiveCell.Offset(-3, 0).Value Then
    MsgBox "Equals"
  else
    MsgBox "Not equal"
  end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top