Compile error for without next vba

roynaz11

New Member
Joined
Jun 23, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
kindly help me to resolve getting this error
Compile error for without next vba

VBA Code:
Sub DataRefine()

Dim MyFolder As String
Dim MyFile As String
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim iRow As Long

Set ws1 = ThisWorkbook.Worksheets("Data")
Set ws2 = ThisWorkbook.Worksheets("Dash")
MyFolder = "C:\****"
MyFile = Dir(MyFolder & "\*.xls")
Do While MyFile <> ""
    Workbooks.Open Filename:=MyFolder & "\" & MyFile
    MyFile = Dir
Loop
Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
        ws.Visible = xlSheetVisible
With ws1
Workbooks.Open "C:\****"\Downloads\C****".xlsx"
Sheets("Sheet0").Range("A2:W2099").Copy
Application.DisplayAlerts = False
Workbooks("****".xlsm").Sheets("Data").Range("C2:BJ1900").PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Range("A1").Select
    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
    Columns("B:B").Select
    Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
End With
Application.ScreenUpdating = True

With ws2
Sheets("Dash").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End With
Workbooks("Car state.xlsx").Close SaveChanges:=False

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
You need a Next like
VBA Code:
    For Each ws In ActiveWorkbook.Worksheets
        ws.Visible = xlSheetVisible
   Next ws
With ws1
Also some of your quotes are out of place.
 

roynaz11

New Member
Joined
Jun 23, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
You need a Next like
VBA Code:
    For Each ws In ActiveWorkbook.Worksheets
        ws.Visible = xlSheetVisible
   Next ws
With ws1
Also some of your quotes are out of place.
can you pls revise still unable to get it.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows
What error are you getting now?
 

roynaz11

New Member
Joined
Jun 23, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Hi & welcome to MrExcel.
You need a Next like
VBA Code:
    For Each ws In ActiveWorkbook.Worksheets
        ws.Visible = xlSheetVisible
   Next ws
With ws1
Also some of your quotes are out of place.
by the way thanks for replying, new to VBA. can you pls update the whole thing.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

What is highlighted?
 

roynaz11

New Member
Joined
Jun 23, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
What is highlighted?
Resolved, it was Sub which was highlighted. The main issue was with the code as i was trying to run from two sub sheets, solution was to make separate modules the run them separately via main macro.
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,548
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback.
 

Forum statistics

Threads
1,141,619
Messages
5,707,435
Members
421,508
Latest member
someinternetuser

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