Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2015, 10:57 PM
ubns ubns is offline Excel Macro Causing the Formatting to change to Default Windows 7 32bit Excel Macro Causing the Formatting to change to Default Office 2010 32bit
Competent Performer
Excel Macro Causing the Formatting to change to Default
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default Excel Macro Causing the Formatting to change to Default

I have an excel macro that is causing to typed content to change to default, so for example if I have entered something in italics, it would change it to normal once I press enter.

Can someone please let me know how I can change this macro to avoid this.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect ("")
If Target.Row > 4 And Target.Column = 7 Then
    Application.EnableEvents = False
    Target = Target & vbLf & " "
    Application.EnableEvents = True
End If
If Target.Address = "$g$5" Then
        Call AutofitRows
    End If

ActiveSheet.Range("g5:g35000").WrapText = True
ActiveSheet.Protect (""), Contents:=True, Scenarios:=True, AllowFormattingRows:=True, AllowFiltering:=True, UserInterfaceOnly:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True
End Sub

Reply With Quote
  #2  
Old 03-29-2015, 01:07 PM
charlesdh charlesdh is offline Excel Macro Causing the Formatting to change to Default Windows 7 32bit Excel Macro Causing the Formatting to change to Default Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

You have a call procedure what does it do?
As for what you posted I could not reproduce the problem that you mentioned.
Reply With Quote
  #3  
Old 03-29-2015, 05:21 PM
ubns ubns is offline Excel Macro Causing the Formatting to change to Default Windows 7 32bit Excel Macro Causing the Formatting to change to Default Office 2010 32bit
Competent Performer
Excel Macro Causing the Formatting to change to Default
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

AutoFit Function is the below. What can I change in this so that it does not change to default formatting.

Code:
Public Sub AutofitRows()
    Dim rng As Range
    Set rng = ThisWorkbook.Worksheets("projectandbau").Rows("1:5000")
    rng.Autofit
       
End Sub
Reply With Quote
  #4  
Old 03-29-2015, 05:36 PM
ubns ubns is offline Excel Macro Causing the Formatting to change to Default Windows 7 32bit Excel Macro Causing the Formatting to change to Default Office 2010 32bit
Competent Performer
Excel Macro Causing the Formatting to change to Default
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

sorry guys, tested again. Its definitely something in this code and NOT IN AUTOFITROWS()

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect ("")
If Target.Row > 4 And Target.Column = 7 Then
    Application.EnableEvents = False
    Target = Target & vbLf & " "
    Application.EnableEvents = True
End If
If Target.Address = "$g$5" Then
     '  Call AutofitRows
    End If

ActiveSheet.Range("g5:g35000").WrapText = True
ActiveSheet.Protect (""), Contents:=True, Scenarios:=True, AllowFormattingRows:=True, AllowFiltering:=True, UserInterfaceOnly:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True
End Sub
Reply With Quote
  #5  
Old 03-29-2015, 06:22 PM
ubns ubns is offline Excel Macro Causing the Formatting to change to Default Windows 7 32bit Excel Macro Causing the Formatting to change to Default Office 2010 32bit
Competent Performer
Excel Macro Causing the Formatting to change to Default
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Actually its application.enable events thats causing it. I have tested it thoroughly. Any idea how to overcome it without removing the use of Application.enableevents.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VBA to change styles causing TabStop problem rjrichar40 Word VBA 2 08-12-2014 10:35 AM
Change Default Excel Grid to Solid Black Lines SQLUSA Word 1 07-15-2012 10:04 PM
Excel Macro Causing the Formatting to change to Default Importing Styles causing odd formatting problems. Red Pill Word 3 06-12-2012 06:19 AM
Excel Macro Causing the Formatting to change to Default How do I change default cinque8 Word 5 06-08-2012 11:18 AM
How do I change default log-in info? RainPure Office 0 11-15-2010 05:07 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft