abdulsamad
08-15-2020, 10:52 PM
Hi I am creating a code for automating a creation of invoice but I am in problem
I wanted to make a onclick event with dynamic range but when I run the code the whole code crashes
Here is the code
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim total As Integer
Range("A1").Select
Selection.End(xlDown).Select
total = ActiveCell.Value
If Target.Cells.CountLarge <> 1 Then Exit Sub
If Not Intersect(Target, Range("H2:H" & (total + 1))) Is Nothing Then
Application.EnableEvents = False
If Target = 1 Then
Target = 0
Else
Target = 1
End If
Application.EnableEvents = True
Range("A1").Select
End If
End Sub
I wanted to make a onclick event with dynamic range but when I run the code the whole code crashes
Here is the code
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim total As Integer
Range("A1").Select
Selection.End(xlDown).Select
total = ActiveCell.Value
If Target.Cells.CountLarge <> 1 Then Exit Sub
If Not Intersect(Target, Range("H2:H" & (total + 1))) Is Nothing Then
Application.EnableEvents = False
If Target = 1 Then
Target = 0
Else
Target = 1
End If
Application.EnableEvents = True
Range("A1").Select
End If
End Sub