Compile error for without next vba

roynaz11

New Member
Joined
Jun 23, 2021
Messages
7
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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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.
 
Upvote 0
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.
 
Upvote 0
What error are you getting now?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
Solution
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

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