Merging two worksheet change codes,now confused

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,279
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I have two codes which both need to be under the Private Sub Worksheet_Change(ByVal Target As Range)

Like normal ive got into a mess & now confused.
Could you advise where ive gone wrong please.

Thanks.
Merged code supplied below

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Target.Address = "$A$6" Then
Application.EnableEvents = False
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
Application.EnableEvents = True
Else
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
 
The recorded macro is shown below.
Had to alter the range to allow sorting etc.

I now need to make this cleaner then add it to the code above for my finished project so far.

Thanks for your help.

Code:
    Range("CG2:CG500").Select
    ActiveWorkbook.Worksheets("INFO").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("INFO").Sort.SortFields.Add Key:=Range("CG3:CG500"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("INFO").Sort
        .SetRange Range("CG2:CG500")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,216,109
Messages
6,128,876
Members
449,476
Latest member
pranjal9

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top