Thread: Moving a number
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
programmernovice[_2_] programmernovice[_2_] is offline
external usenet poster
 
Posts: 61
Default Moving a number

On Tuesday, November 10, 2020 at 11:12:00 PM UTC-6, Auric__ wrote:
programmernovice wrote:

Say I have the number "2" in cell A1 of sheet "Assets". Can someone
please provide a simple vba command for:

1. Entering the contents of cell A1 into cell A5 of "Assets"

Sheets("Assets").Range("A5").Value = Sheets("Assets").Range("A1").Value
2. Entering the contents of cell A1 of "Assets" into cell A5 of sheet
"Liabilities".

Sheets("Liabilities").Range("A5").Value = Sheets("Assets").Range("A1").Value

(In VBA, an underscore ("_") by itself at the end of a line is a line-
continuation character.)
In the old (pre-Vba Excel) macro language which I am familiar with the
command "Formula" was used, however, it does not appear to available in
VBA.

In VBA, the .Formula property refers to, somewhat obviously, the formula,
while the .Value property refers to the displayed value. So, if A1 has a
formula of =1+1, then

Cells(1, 1).Value = 2
Cells(1, 1).Formula = "=1+1"

(Cells(1, 1) is how you refer to cells in R1C1 format. Range("A1") is of
course the other way. R1C1 is easier for me since I do a lot of looping
through every cell in a given column/row/sheet.)
I greatly appreciate all help.

It might be worth reading through a beginner's introduction the VBA. Googling
that phrase should be useful. Wikibooks has a few, but the ones I looked at
don't seem to be for beginners.

--
Power attracts the corruptible. Suspect all who seek it.


Many thanks, Auric, for the excellent, thorough explanation. Do you have an opinion on a good beginners VBA book?

I greatly appreciate your helping me out.