ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If a cell does not contain a formula then... (https://www.excelbanter.com/excel-programming/347679-if-cell-does-not-contain-formula-then.html)

Matt

If a cell does not contain a formula then...
 
Column D accepts "Y" or "N"....If "Y" is chosen then a formula is entered
into column A of the same row. If "N" is chosen, then the contents of the
cell in column A are removed.
A user can put his/her own entry into the cell in column A....is there a way
that excel can recognize whether the cell contains a formula or a
value....and if the cell does not contain a formula to change the cell in
column D to "N"?

Leith Ross[_355_]

If a cell does not contain a formula then...
 

Hello Matt,

You need to use the SelectionChange event of the Worksheet to test th
cell the user has selected. Each worksheet has it's own events so, i
you plan to use this on multiple worksheets, you must include this cod
on each one.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim R As Long

R = Target.Row

If Target.Column = 1 Then
If Target.HasFormula = True Then
Cells(R, "D").Value = "Y"
Else
Cells(R, "D").Value = "N"
End If
End If

End Sub


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=49202


Rowan Drummond[_3_]

If a cell does not contain a formula then...
 
You probably want to change that to a Worksheet_Change Event. If you use
the selection change the user will select a cell in column A which
contains a formula, the event will fire and a Y will be inserted into
column D. The user then types a number over the formula in the selected
cell and the Y stays in Column D as the selection hasn't changed.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim R As Long
If Target.Count = 1 Then

R = Target.Row

If Target.Column = 1 And Target.HasFormula = True Then
Cells(R, "D").Value = "Y"
Else
Cells(R, "D").Value = "N"
End If
End If

End Sub

Hope this helps
Rowan

Leith Ross wrote:
Hello Matt,

You need to use the SelectionChange event of the Worksheet to test the
cell the user has selected. Each worksheet has it's own events so, if
you plan to use this on multiple worksheets, you must include this code
on each one.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim R As Long

R = Target.Row

If Target.Column = 1 Then
If Target.HasFormula = True Then
Cells(R, "D").Value = "Y"
Else
Cells(R, "D").Value = "N"
End If
End If

End Sub


Sincerely,
Leith Ross




All times are GMT +1. The time now is 09:00 AM.

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