opening csv files in separate worksheets

algae

New Member
Joined
Jul 30, 2013
Messages
13
hello experts,

i have this macro to open a number of csv files. Problem is that it opens all the files in one worksheet. Could you add a few lines to the macro to open them in separate worksheets of the excel file. i would be grateful for the help.
Thanks
:)
HTML:
Sub BulkImport()'' BulkImport Macro
         Dim nxt_row As Long          'Change Path    Const strPath As String = "C:\My Documents\IEOD\"  '"ENTER FILE PATH HERE WITH A TRAILING \ e.g: C:\Test\"    Dim strExtension As String          'Stop Screen Flickering    Application.ScreenUpdating = False         ChDir strPath          'Change extension    strExtension = Dir(strPath & "*.txt")         Do While strExtension <> ""                  'Adds File Name as title on next row        Range("A65536").End(xlUp).Offset(1, 0).Value = strExtension                  'Sets Row Number for Data to Begin        nxt_row = Range("A65536").End(xlUp).Offset(1, 0).Row                  'Below is from a recorded macro importing a text file        With ActiveSheet.QueryTables.Add(Connection:= _            "TEXT;" & strPath & strExtension, Destination:=Range("$A$" & nxt_row))            .Name = strExtension            .FieldNames = True            .RowNumbers = False            .FillAdjacentFormulas = False            .PreserveFormatting = True            .RefreshOnFileOpen = False            .RefreshStyle = xlInsertDeleteCells            .SavePassword = False            .SaveData = True            .AdjustColumnWidth = True            .RefreshPeriod = 0            .TextFilePromptOnRefresh = False            .TextFilePlatform = 850            .TextFileStartRow = 1            .TextFileParseType = xlDelimited            .TextFileTextQualifier = xlTextQualifierDoubleQuote             'Delimiter Settings:            .TextFileConsecutiveDelimiter = True            .TextFileTabDelimiter = True            .TextFileSemicolonDelimiter = True            .TextFileCommaDelimiter = True            .TextFileSpaceDelimiter = True            .TextFileOtherDelimiter = "="                         .TextFileTrailingMinusNumbers = True            .Refresh BackgroundQuery:=False        End With                 strExtension = Dir    Loop         Application.ScreenUpdating = True     'End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Your code is pretty much unreadable. Can you try posting it again, this time just using the CODE tags (and not HTML CODE tags)?
 
Upvote 0
hello,

i am trying to delete the first two rows (1 and 2) from all worksheets except from ws names "master".
the macro has a few bugs, request if you could de-lice it.

thanks

Sub DeleteRow()
'
' DeleteRow Macro
'
'
For Each ws In Worksheets

If ws <> "Master"


Then

.Range(Rows(1), Rows(2)).EntireRow.Delete



End If
Next ws


Application.DisplayAlerts = False


'
End Sub
 
Upvote 0
Try this:
Code:
Sub DeleteRow()
' DeleteRow Macro

For Each ws In Worksheets
    If ws.Name <> "Master" Then
        ws.Rows("1:2").Delete
    End If
Next ws

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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