Cancel merged columns and arrange structure across files in the folders

Abdo

Board Regular
Joined
May 16, 2022
Messages
245
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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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
as I 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.
no this is based on recorded macro what I got .
 
Upvote 0
yes and your code delete columns without move to target location !
 
Upvote 0
Then I am not clear on what you want moved and what you want removed.
So let's approach it from this angle.

Make a two column table and post it here.
In the first column, list all the columns that are on the sheet initially, i.e. A, B, C, D, etc all the way to the last column you have with data.
In the second column, indicate where each of these columns should reside when finished, i.e. which column they should be in, or if they should be deleted altogether.

That should remove any doubt about what you are trying to do, and then we can make sure that the code does that.
 
Upvote 0
after cancel merged cells
here is example.
before
ABB.xlsm
ABCDEFGHIJKLMN
1ITEMREF NOBRANDDDT.NOFIRSTSECONDNAMEINPUTOUTPUTNOTE
21ESS 00VBGTL100D#HSD0001SS1233AAB12000250##1
32ESS 01VBGTL101D#HSD0002SS1234AAB230000150
43ESS 02VBGTL102D#HSD0003SS1235AAB34000120
54ESS 03VBGTL103D#HSD0004SS1236AAB43200130##CV
65ESS 04VBGTL104D#HSD0005SS1237AAB51200140
76ESS 05VBGTL105D#HSD0006SS1238AAB61300150
87ESS 06VBGTL106D#HSD0007SS1239AAB71500160##$SD
98ESS 07VBGTL107D#HSD0008SS1240AAB81600170
109ESS 08VBGTL108D#HSD0009SS1241AAB917008
1110ESS 09VBGTL109D#HSD0010SS1242AAB10180058
ss




ABB.xlsm
ABCDEFGHIJKLMN
1DATEINVOICE NOBATCH NOCONDITION NOCOMPANY NAMECUSTOMER NOIMPORTEXPORTREF NOTOTAL
201/01/2024AXCD344VFGT555CDFFRAQ1AZXSDDO12000100REE#1900
302/01/2024AXCD345VFGT556SDERRAQ2AZXSDDO230020REE#280
403/01/2024AXCD346VFGT557ASWERAQ3AZXSDDO3132050REE#1270
504/01/2024AXCD347VFGT558ASDFRAQ4AZXSDDO410010REE#90
605/01/2024AXCD348VFGT559AGGGAQ5AZXSDDO522010REE#210
706/01/2024AXCD349VFGT560ERRRAQ6AZXSDDO6220100REE#120
AQ




after

ABB.xlsm
ABCDEFGH
1ITEMBRANDFIRSTNAMEINPUTSECONDOUTPUTNOTE
21VBGTL100HSD0001AAB12000SS1233250##1
32VBGTL101HSD0002AAB230000SS1234150
43VBGTL102HSD0003AAB34000SS1235120
54VBGTL103HSD0004AAB43200SS1236130##CV
65VBGTL104HSD0005AAB51200SS1237140
76VBGTL105HSD0006AAB61300SS1238150
87VBGTL106HSD0007AAB71500SS1239160##$SD
98VBGTL107HSD0008AAB81600SS1240170
109VBGTL108HSD0009AAB91700SS12418
1110VBGTL109HSD0010AAB101800SS124258
ss




ABB.xlsm
ABCDEFG
1DATEBATCH NOCOMPANY NAMEIMPORTEXPORTREF NOTOTAL
201/01/2024VFGT555AQ12000100REE#1900
302/01/2024VFGT556AQ230020REE#280
403/01/2024VFGT557AQ3132050REE#1270
504/01/2024VFGT558AQ410010REE#90
605/01/2024VFGT559AQ522010REE#210
706/01/2024VFGT560AQ6220100REE#120
AQ


should keep formatting and delete unwanted columns.
 
Upvote 0
I have no idea what you posted, why there are two very different images for before and after (two very different formats), unless you are introducting new layers of complexity you did not mention before.

But you seemed to totally ignore what I requested in my last post (I was looking for a field mapping).
So I don't think there is anything I can really do with what you posted.
 
Upvote 0
why there are two very different images for before and after (two very different formats)
because the thread title contains arranging again .
Cancel merged columns and arrange structure across files in the folders
and I have ever mentioned in OP !:eek:
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 normally you see change in location .:cautious:
I see you don't understand my thread totally despite of I I gave you example!:unsure:
So I don't think there is anything I can really do with what you posted.
it's not problem I will wait for others members to help or post in another forum If I don't getting solution.
anyway thank you for your time.
 
Upvote 0

Forum statistics

Threads
1,226,474
Messages
6,191,221
Members
453,648
Latest member
graduateguardian

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