Macro for summary making

sujan7788

New Member
Joined
Dec 3, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Sub Import_Text_Files()

Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim sDelimiter As String


Application.ScreenUpdating = False


sDelimiter = "|"


FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.PRO), *.PRO", _
MultiSelect:=True, Title:="Text Files to Open")


If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
End If


x = 1
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
wkbTemp.Sheets(1).Copy
Set wkbAll = ActiveWorkbook
wkbTemp.Close (False)
wkbAll.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=False, Semicolon:=False, _
Comma:=True, Space:=True, _
Other:=False, OtherChar:=","
x = x + 1


While x <= UBound(FilesToOpen)
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
With wkbAll
wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=True, _
Other:=False, OtherChar:=sDelimiter
End With
x = x + 1
Wend
Application.ScreenUpdating = True

Rows(4).EntireRow.Delete
Rows(3).EntireRow.Delete
Rows(2).EntireRow.Delete
Rows(1).EntireRow.Delete
Columns("A:A").EntireColumn.Delete
Range("A1").EntireRow.Insert
Cells(1, 1).Value = "Sum"

End Sub


Hi, I want to upload some text files in . PRO format. i was able to do it.But then i wanted to perform the bolted actions on all those worksheets. but its performed only on 1 worksheet. Please provide me advice to do the bolted ones on all the worksheets.
Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You can try replacing your bolded lines with this:-
VBA Code:
    Dim sht As Worksheet
    For Each sht In wkbAll.Worksheets
        With sht
            .Rows(4).EntireRow.Delete
            .Rows(3).EntireRow.Delete
            .Rows(2).EntireRow.Delete
            .Rows(1).EntireRow.Delete
            .Columns("A:A").EntireColumn.Delete
            .Range("A1").EntireRow.Insert
            .Cells(1, 1).Value = "Sum"
        End With
    Next sht
 
Upvote 0
Sub Import_Text_Files()

Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim sDelimiter As String


Application.ScreenUpdating = False


sDelimiter = "|"


FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.PRO), *.PRO", _
MultiSelect:=True, Title:="Text Files to Open")


If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
End If


x = 1
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
wkbTemp.Sheets(1).Copy
Set wkbAll = ActiveWorkbook
wkbTemp.Close (False)
wkbAll.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=False, Semicolon:=False, _
Comma:=True, Space:=True, _
Other:=False, OtherChar:=","
x = x + 1


While x <= UBound(FilesToOpen)
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
With wkbAll
wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=True, _
Other:=False, OtherChar:=sDelimiter
End With
x = x + 1
Wend
Application.ScreenUpdating = True

Dim sht As Worksheet
For Each sht In wkbAll.Worksheets
With sht
.Rows(4).EntireRow.Delete
.Rows(3).EntireRow.Delete
.Rows(2).EntireRow.Delete
.Rows(1).EntireRow.Delete
.Columns("A:A").EntireColumn.Delete
.Range("A1").EntireRow.Insert
.Cells(1, 1).Value = "Sum"
End With
Next sht



End Sub

Hi i tried like this. Gives the same problem. thanks for help
 

Attachments

  • Screenshot (382).png
    Screenshot (382).png
    151.2 KB · Views: 7
  • Screenshot (383).png
    Screenshot (383).png
    106.8 KB · Views: 6
Upvote 0
Please use the vba button when you post code, so it's easier to read.
Is the data on multiple sheets or multiple workbooks ?
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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