ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting Started - Referencing Cells (https://www.excelbanter.com/excel-programming/343874-getting-started-referencing-cells.html)

Tatakau

Getting Started - Referencing Cells
 
Hey,

I've been coding a bit in Access lately, so I know the basics of VB. What I
don't know is how to reference specific cells. I know that the current
column is '.column', and the current row is '.row', and the value of the
current cell is '.value'.

I am trying to assign a value to the cell right below the current cell. I'd
like to do something like this:

(.column, .row + 1).value = 2 * x + 1

Anyone know how to code this?

Thanks!

Nick

Tom Ogilvy

Getting Started - Referencing Cells
 
ActiveCell.offset(1,0).Value = 2 * x + 1

--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
Hey,

I've been coding a bit in Access lately, so I know the basics of VB. What

I
don't know is how to reference specific cells. I know that the current
column is '.column', and the current row is '.row', and the value of the
current cell is '.value'.

I am trying to assign a value to the cell right below the current cell.

I'd
like to do something like this:

(.column, .row + 1).value = 2 * x + 1

Anyone know how to code this?

Thanks!

Nick




Tatakau

Getting Started - Referencing Cells
 
That did it!

Though I had to use an offset of (0,0) to assign a value to a cell that was
right below the current cell, instead of (1,0)... not sure why. Guess it's
just the coding convention.

Thanks!

Nick

"Tom Ogilvy" wrote:

ActiveCell.offset(1,0).Value = 2 * x + 1

--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
Hey,

I've been coding a bit in Access lately, so I know the basics of VB. What

I
don't know is how to reference specific cells. I know that the current
column is '.column', and the current row is '.row', and the value of the
current cell is '.value'.

I am trying to assign a value to the cell right below the current cell.

I'd
like to do something like this:

(.column, .row + 1).value = 2 * x + 1

Anyone know how to code this?

Thanks!

Nick





Tom Ogilvy

Getting Started - Referencing Cells
 
No, Offset is zero based.

If you had to use 0,0, then there is a miscommunication.

demo'd from the immediate window in the VBE:

? Range("A1").Offset(0,0).Address
$A$1
? Range("A1").Offset(1,0).Address
$A$2


--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
That did it!

Though I had to use an offset of (0,0) to assign a value to a cell that

was
right below the current cell, instead of (1,0)... not sure why. Guess

it's
just the coding convention.

Thanks!

Nick

"Tom Ogilvy" wrote:

ActiveCell.offset(1,0).Value = 2 * x + 1

--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
Hey,

I've been coding a bit in Access lately, so I know the basics of VB.

What
I
don't know is how to reference specific cells. I know that the

current
column is '.column', and the current row is '.row', and the value of

the
current cell is '.value'.

I am trying to assign a value to the cell right below the current

cell.
I'd
like to do something like this:

(.column, .row + 1).value = 2 * x + 1

Anyone know how to code this?

Thanks!

Nick







Tatakau

Getting Started - Referencing Cells
 
Ahhhh whoops. Alright, I don't know if the Offset command is going to work
for me. It looks like when I use the .Offset command, it doesn't use the
cell that I had just edited - it uses the cell that I move to AFTER I edit a
cell. Which just doesn't work.

So I should probabl rephrase the question: I want to change the value of a
cell with column X and row Y. How do I code that?

Thanks,

Nick

"Tom Ogilvy" wrote:

No, Offset is zero based.

If you had to use 0,0, then there is a miscommunication.

demo'd from the immediate window in the VBE:

? Range("A1").Offset(0,0).Address
$A$1
? Range("A1").Offset(1,0).Address
$A$2


--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
That did it!

Though I had to use an offset of (0,0) to assign a value to a cell that

was
right below the current cell, instead of (1,0)... not sure why. Guess

it's
just the coding convention.

Thanks!

Nick

"Tom Ogilvy" wrote:

ActiveCell.offset(1,0).Value = 2 * x + 1

--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
Hey,

I've been coding a bit in Access lately, so I know the basics of VB.

What
I
don't know is how to reference specific cells. I know that the

current
column is '.column', and the current row is '.row', and the value of

the
current cell is '.value'.

I am trying to assign a value to the cell right below the current

cell.
I'd
like to do something like this:

(.column, .row + 1).value = 2 * x + 1

Anyone know how to code this?

Thanks!

Nick







Tom Ogilvy

Getting Started - Referencing Cells
 
Cells(.row + 1,.column).Value = 2 * x + 1

However, if you can get .row and .column then this is the long way around
the block.

It sounds like you are using the change event and using ActiveCell instead
of target.

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox ActiveCell.Address & " - " & Target.Address
End Sub

Target holds the reference to the cell that triggered the event.

--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
Ahhhh whoops. Alright, I don't know if the Offset command is going to

work
for me. It looks like when I use the .Offset command, it doesn't use the
cell that I had just edited - it uses the cell that I move to AFTER I edit

a
cell. Which just doesn't work.

So I should probabl rephrase the question: I want to change the value of

a
cell with column X and row Y. How do I code that?

Thanks,

Nick

"Tom Ogilvy" wrote:

No, Offset is zero based.

If you had to use 0,0, then there is a miscommunication.

demo'd from the immediate window in the VBE:

? Range("A1").Offset(0,0).Address
$A$1
? Range("A1").Offset(1,0).Address
$A$2


--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
That did it!

Though I had to use an offset of (0,0) to assign a value to a cell

that
was
right below the current cell, instead of (1,0)... not sure why. Guess

it's
just the coding convention.

Thanks!

Nick

"Tom Ogilvy" wrote:

ActiveCell.offset(1,0).Value = 2 * x + 1

--
Regards,
Tom Ogilvy


"Tatakau" wrote in message
...
Hey,

I've been coding a bit in Access lately, so I know the basics of

VB.
What
I
don't know is how to reference specific cells. I know that the

current
column is '.column', and the current row is '.row', and the value

of
the
current cell is '.value'.

I am trying to assign a value to the cell right below the current

cell.
I'd
like to do something like this:

(.column, .row + 1).value = 2 * x + 1

Anyone know how to code this?

Thanks!

Nick










All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com