1

I can not achieve to do what looks like an easy process... I would like to give a value ("Hello") to a cell (named "ClInfo") in sheet named "Hardware" by a click on a cell (C47) in sheet named "1".

I tried this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
    If Not Intersect(Target, Range("C47")) Is Nothing Then
        .range("ClInfo").value = "hello"
    End If
End If 

What should I do to make it works? Thanks for your help!

1

Your code could look like the following, it looks like you're just missing the Worksheet object:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("C47")) Is Nothing Then
        Worksheets("Hardware").Range("ClInfo").Value = "hello"
        End If
    End If
End Sub

Make sure you're placing this as the VBA for your sheet named 1:

enter image description here

  • Thanks! it does work now. For no reason, I tried that before but did not achieve to make it works, probably a misspell something... thx again! – Adrien de Harlez Mar 14 '16 at 2:00
  • Still needs some help... The solution above fully worked! But I have now another issue. The target range needs to be cell and merged cells... I know... merge cell are really to avoid, but cannot do any other way for this dashboard. I tried everything that I saw (mergearea, cell(1)... but nothing seems to work. Any idea? Btw, thx @Jonno, I just noticed you are the one helping for both question I posted :) – Adrien de Harlez Mar 18 '16 at 15:24
  • No one got an idea for that? – Adrien de Harlez Mar 20 '16 at 9:40
  • @AdriendeHarlez Sorry, I didn't see this before. What exactly are you struggling with? Copying the value into a merged cell? – Jonno Mar 20 '16 at 9:44
  • Hi @Jonno. I'd like to target merged cell. So in (your) screenshot above, let'say the target would be : range("C47:E47") instead of range("C47") because C:E are merged. When I do that, nothing happens. Like if the script does not notice I select those merged cells... What can I do ? thx!! – Adrien de Harlez Mar 21 '16 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.