ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Evening,
I currently use this code shown below on a click command button.
I would like the code to run BUT i dont want to keep clicking the button so it needs to be a change event ??
I assume i need to add it to my currently used change event which is shown below.
I tried like shown but as soon as you move anywhere on the sheet the code runs where i thought it would only rune once you leave cell A6
If im totally wrong & It needs to be something else please advise.
Thanks
I currently use this code shown below on a click command button.
Code:
Private Sub CommandButton1_Click()Dim CustomerName As String
Worksheets("DATABASE").Select
CustomerName = Range("A6")
Worksheets("INFO").Select
Worksheets("INFO").Range("CF2").Select
If Worksheets("INFO").Range("CF2").Offset(1, 0) <> "" Then
Worksheets("INFO").Range("CF2").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = CustomerName
ActiveCell.Interior.ColorIndex = 6
ActiveCell.HorizontalAlignment = xlCenter
ActiveCell.VerticalAlignment = xlBottom
ActiveCell.VerticalAlignment = xlCenter
Selection.Borders.LineStyle = xlContinuous
ActiveCell.RowHeight = 19.5
ActiveCell.Font.Bold = True
Worksheets("DATABASE").Select
End Sub
I would like the code to run BUT i dont want to keep clicking the button so it needs to be a change event ??
I assume i need to add it to my currently used change event which is shown below.
Code:
Private Sub Worksheet_Change(ByVal Target As Range) With Target
If .Column = 13 Then Exit Sub
If .Count = 1 And Not .HasFormula Then
Application.EnableEvents = False
.Value = UCase(.Value)
Application.EnableEvents = True
End If
End With
End Sub
I tried like shown but as soon as you move anywhere on the sheet the code runs where i thought it would only rune once you leave cell A6
Code:
Private Sub Worksheet_Change(ByVal Target As Range) With Target
If .Column = 13 Then Exit Sub
If .Count = 1 And Not .HasFormula Then
Application.EnableEvents = False
.Value = UCase(.Value)
Application.EnableEvents = True
Else
Dim CustomerName As String
Worksheets("DATABASE").Select
CustomerName = Range("A6")
Worksheets("INFO").Select
Worksheets("INFO").Range("CF2").Select
If Worksheets("INFO").Range("CF2").Offset(1, 0) <> "" Then
Worksheets("INFO").Range("CF2").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = CustomerName
ActiveCell.Interior.ColorIndex = 6
ActiveCell.HorizontalAlignment = xlCenter
ActiveCell.VerticalAlignment = xlBottom
ActiveCell.VerticalAlignment = xlCenter
Selection.Borders.LineStyle = xlContinuous
ActiveCell.RowHeight = 19.5
ActiveCell.Font.Bold = True
Worksheets("DATABASE").Select
End If
End With
End Sub
If im totally wrong & It needs to be something else please advise.
Thanks