Code causes crash

Newbienew

Active Member
Joined
Mar 17, 2017
Messages
395
Office Version
  1. 2016
Platform
  1. Windows
So i am having an issue with a code that I was using. It makes everything capitalize on the page no matter where. Bu when I use code now it freezes the workbook and then crashes it. Is there anything I can do about this? I have provided the code that i use below



Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range
For Each R In Target
If Not IsEmpty(R) And Not R.HasFormula Then R.Value = UCase(R.Value)
Next R
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,
why do you use Worksheet_Change Event? Now everytime you change something in the worksheet the code gets driggerd.
So you should put the code into a module and then run the code and that is it.
 
Upvote 0
If I am not mistaken, I pasted this code in VBA module and hit the run button and that is it. Is this what you are speaking off?
 
Upvote 0
This type code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range
For Each R In Target
If Not IsEmpty(R) And Not R.HasFormula Then R.Value = UCase(R.Value)
Next R
End Sub

Is not the type code which will run when you click a button.
 
Upvote 0
Because you are changing the value in a cell, that triggers the code to run again & again & again in a permanent loop.
Try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim R As Range
   Application.EnableEvents = False
   For Each R In Target
      If Not IsEmpty(R) And Not R.HasFormula Then R.Value = UCase(R.Value)
   Next R
   Application.EnableEvents = True
End Sub
 
Upvote 0
@My Aswer Is This- Yes it think it was made to do eh loop thing again and again. So I would be able to type and everything would capitalize after I moved to the next cell
@Fluff- I attempted to use your new coding but it would seem it didnt work out for me. I am not sure if i did something wrong. I put it in a module, click run and saved it as a Macro.

The last code i just placed in in the module hit run and that was it worked ever since, until it started crashing excel
 
Upvote 0
Show us the exact code you last used and which you said crashed Excel.

The code Fluff provided does not go in a Module. It is a sheet event script and is installed like this:

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

The code runs any time you change any value in your worksheet.
 
Last edited:
Upvote 0
The code i used is in the very first posting. When I change the cell and hit enter excel would freeze and then say not responding then close
 
Upvote 0
Several here have said you should not use the code in post #1

And you said:
If I am not mistaken, I pasted this code in
VBA module and hit the run button
and that is it. Is this what you are speaking off?

I said earlier this type code does not go in a Button.

What did not work for you when using Fluff code in post #5

Do not put Fluff code in a button.
Install it like this:

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

The code runs any time you change any value in your worksheet.



 
Upvote 0
My humblest apologies I did not see several here. I have not made any buttons to use this code. I copy and paste in a module, hit the run button that is in the view code window and close.

The code that Fluffy provided I copied and pasted and did the same thing. This time a window popped up Looking for a name for macro.

My correction to this was the workbook that i was working with was not saved as a macro and when i ran the code this time i close the window without clicking anything.

It worked out for me the second time around Thank you so much for the help and assistance
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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