Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2022, 12:49 PM
jjxxoo jjxxoo is offline Microsoft visual basic: Compile error expected end with Mac OS X Microsoft visual basic: Compile error expected end with Office 2021
Novice
Microsoft visual basic: Compile error expected end with
 
Join Date: Dec 2022
Posts: 1
jjxxoo is on a distinguished road
Default Microsoft visual basic: Compile error expected end with


MICROSOFT VISUAL BASIC: COMPILE ERROR EXPECTED END WITH
I am expected to fix this code but am unsure how i keep rearranging things but get error codes and it wont let me run the code. If someone can help please.


Code:
Sub Formatting()
 
 ' Objective
 ' Name
 ' Date
 
    With Worksheets("Formatting")
        
        With .Range("A1")
            .Value = "Expenses For March"
            With .Font
                .Name = "Arial"
                .Bold = True
                .ColorIndex = 5
                .Size = 14
         End With
         
          With .Interior
                .ColorIndex = 2
            End With
            
            .HorizontalAlignment = xlLeft
        End With
        
        With Range("A3:A6")
            .InsertIndent 1
            With .Font
                .Italic = True
                .Bold = True
                .ColorIndex = 3
            End With
            
            With .Range("B3:B6")
                .Interior.ColorIndex = 37
                .NumberFormat = "$#,##0"
            End With
        
        End With 

End Sub
Reply With Quote
  #2  
Old 12-01-2022, 11:57 PM
macropod's Avatar
macropod macropod is offline Microsoft visual basic: Compile error expected end with Windows 10 Microsoft visual basic: Compile error expected end with Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,927
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Not only are you missing the required final 'End With', your 'With .Range("B3:B6") ... End With' block is logically inside your 'With Range("A3:A6") ... End With' block. All this would be readily apparent if you structured your code more consistently and avoided 'With ... End With' blocks containing only one element. For example:
Code:
Sub Formatting()
With Worksheets("Formatting")
    With .Range("A1")
        .Value = "Expenses For March"
        With .Font
            .Name = "Arial"
            .Bold = True
            .ColorIndex = 5
            .Size = 14
        End With
        .Interior.ColorIndex = 2
        .HorizontalAlignment = xlLeft
    End With
    
    With .Range("A3:A6")
        .InsertIndent 1
        With .Font
            .Italic = True
            .Bold = True
            .ColorIndex = 3
        End With
    End With
    
    With .Range("B3:B6")
        .Interior.ColorIndex = 37
        .NumberFormat = "$#,##0"
    End With
End With
End Sub
Your 'With Range("A3:A6") ... End With' block should also be 'With .Range("A3:A6") ... End With'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft visual basic: Compile error expected end with Need help fixing compile error expected End Sub to combine multiple documents into one (Mac) Vivianweir Excel Programming 3 11-02-2018 02:20 AM
Microsoft visual basic for applications - errors occurred during load. aditya1810 Excel Programming 0 06-05-2018 08:37 AM
compile error expected end sub ashg75 Word VBA 2 07-13-2017 07:08 AM
Word Visual Basic error - run time error 504 crazymorton Word 11 01-13-2012 04:32 AM
Microsoft visual basic: Compile error expected end with A little Visual Basic Help Please leroytrolley Excel 4 08-22-2008 03:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:35 PM.


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