Excelfile split with two headings VBA Macro

emm1988

New Member
Joined
May 17, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I need some help with my code. It works ok, but I'm loosing one of my headings in the split, my top one (row1)
row 1 headings are merged columns, B:G "Product" H:M "Actor" N:Q "Follow-up" and R.AI "Report card"
row 2 headings are one for each column.

See the code below, please help me :)


Sub masterlista()

Application.ScreenUpdating = False

Dim data_sh As Worksheet
Set data_sh = ThisWorkbook.Sheets("test1")

Dim setting_sh As Worksheet
Set setting_sh = ThisWorkbook.Sheets("Settings")

Dim nwb As Workbook
Dim nsh As Worksheet

setting_sh.Range("A:A").Clear
data_sh.AutoFilterMode = False
data_sh.Range("A:A").Copy setting_sh.Range("A1")
setting_sh.Range("A:A").RemoveDuplicates 1, x1Yes

Dim i As Integer

For i = 2 To Application.CountA(setting_sh.Range("A:A"))
data_sh.UsedRange.AutoFilter 1, setting_sh.Range("A" & i).Value

Set nwb = Workbooks.Add
Set nsh = nwb.Sheets(1)

data_sh.UsedRange.SpecialCells(xlCellTypeVisible).Copy nsh.Range("A1")

'''''nsh.UsedRange.Rows("1").RowHeight = 15
nsh.UsedRange.Rows("1").RowHeight = 120
nsh.UsedRange.Columns("A").Hidden = True
nsh.UsedRange.Columns("B").ColumnWidth = 25
nsh.UsedRange.Columns("C:D").ColumnWidth = 16
nsh.UsedRange.Columns("E").ColumnWidth = 35
nsh.UsedRange.Columns("F").ColumnWidth = 13
nsh.UsedRange.Columns("G").ColumnWidth = 27
nsh.UsedRange.Columns("H").ColumnWidth = 55
nsh.UsedRange.Columns("I").ColumnWidth = 19
nsh.UsedRange.Columns("J").ColumnWidth = 22
nsh.UsedRange.Columns("K").ColumnWidth = 23
nsh.UsedRange.Columns("L:M").ColumnWidth = 24
nsh.UsedRange.Columns("N:O").ColumnWidth = 79
nsh.UsedRange.Columns("P").ColumnWidth = 18
nsh.UsedRange.Columns("Q").ColumnWidth = 35
nsh.UsedRange.Columns("R").ColumnWidth = 55
nsh.UsedRange.Columns("S:AI").ColumnWidth = 22

nwb.SaveAs setting_sh.Range("H3").Value & "/" & "Översikt av era artiklar som ingick i 2020 års kartläggning_" & setting_sh.Range("A" & i).Value & ".xlsx"
nwb.Close Flase
data_sh.AutoFilterMode = False

Next i

setting_sh.Range("A:A").Clear

MsgBox "Done"

End Sub
 

Attachments

  • VBA.PNG
    VBA.PNG
    18.1 KB · Views: 15

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,755
Messages
6,180,758
Members
452,996
Latest member
nelsonsix66

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