View Single Post
  #6   Report Post  
Neil Goldwasser
 
Posts: n/a
Default

Sorry, one more idea to add to my last one. Let's say my situation is as
described in my last post (which I have not yet managed to write code for,
but if somebody could advise me might be possible):

Cells A1:A100 are the original drop-down list
Cells E1:E100 are the cells that will automatically change to "N/A" if the
corresponding A cell is "N/A"

If I entered "N/A" from the drop-down list into A1, E1 would automatically
turn to "N/A" as well. But I am then able to click on E1 and select a
different value from the drop-down list, overwriting the "N/A". Is there any
way of disallowing this overwrite, so that if A1 is "N/A", E1 stays as "N/A",
even if you try to change it?

It would be even better if a message box could pop up as well and say
something along the lines of "This cell must remain as N/A, because cell the
corresponding A cell is N/A".

If I could add these two new changes (this and the one from my last post)
I'd be over the moon!
Thanks again for the help, it is much appreciated.
Neil



"Neil Goldwasser" wrote:

Perfect! Thanks very much for that! I'm really starting to come around to
macros now.

Am I right in thinking that I might cause problems for this code if I needed
to insert new columns between A & B, so that the cell that needs to
automatically turn to N/A depending on the outcome of A1 is no longer next to
it?

Is there an easy way of adapting the code so that, for example, cells
A1:A100 are the first cells, chosen from a drop-down list, and cells E1:E100
are the ones that need to automatically change to "N/A" if the corresponding
cell in the A-range is "N/A".

Sorry to keep asking so many questions, but since this is my first dabble
with Visual Basic I'm fascinated by it all!

Many thanks again, Neil



"JE McGimpsey" wrote:

There are many ways, here's one:

For column A:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rTarget As Range
Dim rCell As Range
Set rTarget = Intersect(Target, Columns(1))
If Not rTarget Is Nothing Then
For Each rCell In rTarget
If rCell.Value = "N/A" Then
Application.EnableEvents = False
rCell.Offset(0, 1).Value = "N/A"
Application.EnableEvents = True
End If
Next rCell
End If
End Sub

For A1:A100:

Change

Columns(1)

to

Range("A1:A100")



In article ,
Neil Goldwasser <Neil wrote:

Thanks for that - that was great! Just one more question if I may though (I
apologise if the answer is a simple one, I am very much a macro novice!)

How could I adapt this code so that it works not just for cell A1, but for a
range of cells. What would I need to change for this function to work for all
of column A, or for cells A1 to A100, for example.

Many thanks, Neil


"JE McGimpsey" wrote:

I think the only way you can do this is with an event macro, since once
you choose something from the validation menu, any formula will be
overwritten.

Put this in your worksheet code module (right-click on the worksheet tab
and choose View Code):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
If Range("A1").Value = "N/A" Then
Application.EnableEvents = False
Range("B1").Value = "N/A"
Application.EnableEvents = True
End If
End If
End Sub