Expected End With Error

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Expected End With Error

Post by zyxw1234 »

Code: Select all

Sub STEP2()
   Dim Wb1 As Workbook
   Dim WS1 As Worksheet
   Dim WS2 As Worksheet
   Set Wb1 = ThisWorkbook
   Set WS1 = Wb1.Worksheets.Item(2)
   Set WS2 = Wb1.Worksheets.Item(3)
   With WS1
   WS1.Cells.Clear
   With WS2
   WS2.Cells.Clear
   Wb1.Save
   
End Sub

I am getting error plz correct the code & help me in solving this problem Sir





Error Details

https://drive.google.com/open?id=1E1gpY ... h7HAtnnuEG

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Expected End With Error

Post by HansV »

You have two With ... lines without the required corresponding End With lines - precisely what the error message says.
But since you don't use the With blocks anyway, you can simply delete those two lines.
Best wishes,
Hans

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Expected End With Error

Post by zyxw1234 »

With WS1
With WS2


Do u mean to say Should i delete this ?
& Plz let me know deleting this is perfect (the code will be perfect ,workable )

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Expected End With Error

Post by Leif »

zyxw1234 wrote:
21 May 2020, 14:24
I am getting error plz correct the code & help me in solving this problem Sir
Have you ever thought about trying to find out what the problem is yourself?

For example, compile error expected end with - Google Search would probably have taken less time than creating the link to your screenshot and making a post here.
Leif

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Expected End With Error

Post by Leif »

zyxw1234 wrote:
21 May 2020, 15:19
With WS1
With WS2


Do u mean to say Should i delete this ?
What happens if you try it yourself?
Leif

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Expected End With Error

Post by zyxw1234 »

Code: Select all

Sub STEP2()
   Dim Wb1 As Workbook
   Dim WS1 As Worksheet
   Dim WS2 As Worksheet
   Set Wb1 = ThisWorkbook
   Set WS1 = Wb1.Worksheets.Item(2)
   Set WS2 = Wb1.Worksheets.Item(3)
   WS1.Cells.Clear
   WS2.Cells.Clear
   Wb1.Save
   
End Sub


I used this & it is working
Any more changes is required then plz let me know
Thnx HansV Sir & Leif Sir for giving ur Great Support
Have a Great Day