Excel addicted
New Member
- Joined
- Sep 17, 2019
- Messages
- 14
Hello guys,
I have just joined this amazing place and I'm still novice in VBA . From the code below, I would like to display rows number of selected cells in cell "A4". The issue is I have the first number displayed in negative value without parenthesis. However I want to display a positive value between parenthesis.
Is something missing in the code
Thanks for your great help !
I have just joined this amazing place and I'm still novice in VBA . From the code below, I would like to display rows number of selected cells in cell "A4". The issue is I have the first number displayed in negative value without parenthesis. However I want to display a positive value between parenthesis.
Is something missing in the code
Thanks for your great help !
Code:
[COLOR=#111111][FONT=Roboto]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto]If Not Intersect(Target, Range(" D22:I46 ")) Is Nothing Then[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] Dim Cell As Range[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] If Target.Count > 1 And Target.Count < 70 Then[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] For Each Cell In Selection[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] Range("A4").Value = Range("A4").Value & "(" & Cell.Row - 21 & ")"[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] Next Cell[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] Else[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] Range("A4").Value = "(" & Target.Row - 21 & ")"[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto] End If[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto]Else[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto]Range("A4").ClearContents[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto]End If[/FONT][/COLOR][COLOR=#111111][FONT=Roboto][/FONT][/COLOR][COLOR=#111111][FONT=Roboto]End Sub[/FONT][/COLOR]