Cancel merged columns and arrange structure across files in the folders

Abdo

Board Regular
Joined
May 16, 2022
Messages
238
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi,
I would cancel merged columns and cells across all of files are existed in this device"C:\Users\Abdo\Desktop\TYR"
each file contains different counts sheets also I would arrange columns across files from A,C,E,H,M,N,K to A,B,C,D,E,F,G across sheets for each file.
so the macro should be in MASTER file is open , others files are closed .
the result should be for each file is closed , but the macro should in MASTER file
all of files are xls extension .
thanks.
.
 
Record yourself moving them one at a time.
You will only need to do that once, as once you have it in your code, VBA will do all those steps every time.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
how about this try?
VBA Code:
Range("A:A,C:C,E:E,H:H,M:M,N:N,K:K").Select
    Range("K1").Activate
    Selection.Copy
    Columns("A:H").Select
    ActiveSheet.Paste
 
Upvote 0
Did you even try it? That code returns errors for me.
It looks to me like you are copying the value from K1 to column A:H.

You originally said:
I would arrange columns across files from A,C,E,H,M,N,K to A,B,C,D,E,F,G across sheets for each file
It looks like you really just want to move column K to the end and delete a bunch of columns.
If so, this should do that:
VBA Code:
Sub MyFormattingFixMacro()

    Dim pth As String
    Dim ext As String
    Dim fl As String
    Dim wb As Workbook
    Dim ws As Worksheet

    Application.ScreenUpdating = False

'   Enter path and file extension to look for
    pth = "C:\Users\Abdo\Desktop\TYR\"
    ext = "*.xls*"

'   Target path and extension
    fl = Dir(pth & ext)

'   Loop through each Excel file in folder
    Do While fl <> ""
'       Open workbook and assign to object variable
        Set wb = Workbooks.Open(Filename:=pth & fl)
'       Loop through all sheets
        For Each ws In wb.Worksheets
            With ws
'               Move and delete columns
                .Columns("K:K").Copy .Range("O1")
                .Range("B:B,D:D,F:F,G:G,I:I,J:J,K:K,L:L").Delete Shift:=xlToLeft
            End With
        Next ws
'       Close workbook
        wb.Close SaveChanges:=True
'       Get next file name
        fl = Dir
    Loop
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,335
Messages
6,184,338
Members
453,227
Latest member
Slainte

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