ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Easy question - If ...then Change cell value (https://www.excelbanter.com/excel-programming/335883-easy-question-if-then-change-cell-value.html)

Mike R.

Easy question - If ...then Change cell value
 
Greetings,
This seems like such an easy question, but I have searched and just cannot
find the answer.

In my Workbook Open(), I would like to check the value of Q1 and if it = 1,
then change the value to = 2.

I have tried:
If Range("Q39").Value = "1" Then
Range("Q39").Value = "2"
End If

But it errors out... help...
Mike

KL

Easy question - If ...then Change cell value
 
Hi Mike,

Your code works fine to me. If anything I would change the "1" and "2" to 1
and 2 and qualify the range with the sheet name, something like this:

Private Sub Workbook_Open()
With Sheets("Sheet1")
If .Range("Q39").Value = 1 Then
.Range("Q39").Value = 2
End If
End With
End Sub

Regards,
KL


"Mike R." wrote in message
...
Greetings,
This seems like such an easy question, but I have searched and just cannot
find the answer.

In my Workbook Open(), I would like to check the value of Q1 and if it =
1,
then change the value to = 2.

I have tried:
If Range("Q39").Value = "1" Then
Range("Q39").Value = "2"
End If

But it errors out... help...
Mike




Karthik Bhat - Bangalore

Easy question - If ...then Change cell value
 
Hi
Buddy your code is fine but the cell reference in it is wrong. It
should be "Q1" and not "Q39".

If Range("Q1").Value = "1" Then
Range("Q1").Value = "2"
End If


Thanks
Karthik Bhat
Bangalore


William Benson[_2_]

Easy question - If ...then Change cell value
 
It should not be erring out, something else is up with that! Nor should it
matter whether you have quotes around the "1" and "2" as far as I can tell
.... and the fact that you have mixed up Q1 and Q39 seems like an obvious
typo that even if not what you meant, should not be generating an error, it
should just behave in ways you were not desiring,

Bill
"Mike R." wrote in message
...
Greetings,
This seems like such an easy question, but I have searched and just cannot
find the answer.

In my Workbook Open(), I would like to check the value of Q1 and if it =
1,
then change the value to = 2.

I have tried:
If Range("Q39").Value = "1" Then
Range("Q39").Value = "2"
End If

But it errors out... help...
Mike





All times are GMT +1. The time now is 10:28 AM.

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