Activecell value

  • Thread starter Thread starter Shamsul Islam
  • Start date Start date
S

Shamsul Islam

Hi

I want a variable value, to be the value of the activecell.

I've tried the following:

Dim Z As Integer
Z = 0
Z = ActiveCell.Range("A1").Value

The code doesn't work. Please advise.

Thanks

Sham
 
Rob ,

Although it is not necessary, and looks odd, the OP's syntax is not wrong.

What might be wrong is that the activecell might be a string or something,
not an integer.

Shamsul, also you don't need to initialise variables before setting i9t to a
value. Try this

Dim Z As Integer
With ActiveCell.Range("A1")
If IsNumeric(.Value) Then
Z = .Value
End If
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Hi

Thanks for your reply, but it still does not work.

Here is the full macro:

Sub XXXX()

Dim X As Integer
Dim Y As Integer
Dim Z As Integer
Dim ZY As Integer

Let X = Range("A1").Value
Y = -15
ZY = 0
For Counts = 1 To X
Y = Y - 5
Z = 0
Application.Goto Reference:="ProjTotal04"
ActiveCell.Offset(0, Y).Select
Z = ActiveCell.Value
ZY = ZY + Z
Application.Goto Reference:="ProjTotal04"
ActiveCell.Value = ZY
Next
End Sub

Macro alwway stops at Z = ActiveCell.Value

Please help.

Thanks

Sham
 
Is it definitely an integer in that cell? What error message are you
getting?

Jeff
 
My assumption was that the cell content was an integer - I guess I should
have detailed that assumption.

If the cell content type cannot be guaranteed, I would recommend setting
variable to type of Variant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top