Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
622
Office Version
  1. 365
Platform
  1. Windows
hi

have some code in my spreadsheet, that formats a certain area whenever i enter data into any area within. However although it works, it selects and moves the cursor away from the area I am working at . Anyone have a solution?


KR
Trevor
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,374
Office Version
  1. 365
Platform
  1. Windows
Care to post the code?
 

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
622
Office Version
  1. 365
Platform
  1. Windows
ooops sorry :-

Private Sub Worksheet_Change(ByVal Target As Range)

''''''''''''''''''''''''''''''''''''''''''''


'Forces text to UPPER case for the range c6:d14
'Forces text to Proper case for the range K6:K14


''''''''''''''''''''''''''''''''''''''''''''


If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub






On Error Resume Next


If Not Intersect(Target, Range("c6:d18")) Is Nothing Then


Application.EnableEvents = False


Target = UCase(Target)


Application.EnableEvents = True


End If



On Error GoTo 0




If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub






On Error Resume Next


If Not Intersect(Target, Range("n6:n12")) Is Nothing Then


Application.EnableEvents = False


Target = StrConv(Target, vbProperCase)


Application.EnableEvents = True


End If


On Error GoTo 0





'
Range("C6:D13").Select
Application.CutCopyMode = False
With Selection.Font
.Name = "Calibri"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection.Font
.Name = "Calibri"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection.Font
.Name = "Calibri"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With



End Sub
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,930
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows

ADVERTISEMENT

Code:
'
    Range("C6:D13").Select
    Application.CutCopyMode = False
    With Selection.Font
        .Name = "Calibri"
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
    With Selection.Font
        .Name = "Calibri"
        .Size = 12
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
    With Selection.Font
        .Name = "Calibri"
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
You can remove the above part of your code as it is resetting the same range with the same values every time you make a change to a cell on the worksheet. Once this code sets its values and the worksheet has been saved, there is no need to do it again. The first line in this code is selecting a range other than your target cell, so it is responsible for the cursor moving.
 
Last edited:

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
622
Office Version
  1. 365
Platform
  1. Windows
thanks.... works a treat.

many, many thanks.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,063
Messages
5,851,872
Members
431,470
Latest member
mikaelaleksandrowicz

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
Top