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 |
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 |
All times are GMT +1. The time now is 08:02 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com