Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
comparini3000
 
Posts: n/a
Default What Am I Doing Wrong

I'm testing an idea I had. In cells B1, 2, and 3 I have the numbers 1, 2, and
3, respectively. I wrote a macro hoping to put the value 4 in cell C1.
However, this macro is intended to add 1 to the preceding value, so, for
example, if cell B52 has the value 52 in it, the macro will put the value 53
in cell C1. Here's my code:

Sub test()
Dim x As Integer
Range("B1").Select
Selection.End(xlDown).Select
Selection.Value = x
x = x + 1
Range("C1").Select
Selection.Value = x
End Sub

My problem is that the last value (in my test it was 3, in cell B3) was
changed to zero, so the value of 1 was put in C1. What am I doing wrong?

comparini3000
  #2   Report Post  
Posted to microsoft.public.excel.misc
comparini3000
 
Posts: n/a
Default What Am I Doing Wrong

found the error -- the first "selection.value = x" should be "x =
selection.value"

"comparini3000" wrote:

I'm testing an idea I had. In cells B1, 2, and 3 I have the numbers 1, 2, and
3, respectively. I wrote a macro hoping to put the value 4 in cell C1.
However, this macro is intended to add 1 to the preceding value, so, for
example, if cell B52 has the value 52 in it, the macro will put the value 53
in cell C1. Here's my code:

Sub test()
Dim x As Integer
Range("B1").Select
Selection.End(xlDown).Select
Selection.Value = x
x = x + 1
Range("C1").Select
Selection.Value = x
End Sub

My problem is that the last value (in my test it was 3, in cell B3) was
changed to zero, so the value of 1 was put in C1. What am I doing wrong?

comparini3000

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What am I doing wrong? PFB1033 Excel Discussion (Misc queries) 1 February 13th 06 02:13 AM
Wrong Numerical Input zhj23 Excel Discussion (Misc queries) 3 February 12th 06 03:19 AM
SUMPRODUCT is showing wrong Amount msbutton27 Excel Discussion (Misc queries) 2 January 25th 06 03:40 PM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
Logic statement returns wrong answer. Tony Excel Worksheet Functions 2 December 2nd 04 05:07 AM


All times are GMT +1. The time now is 12:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"