Share via

Vba splitbook not including all data

Anonymous
2022-04-05T16:06:26+00:00

I figured out how to separate out the information by the different vendors successfully and it copies the first line or column headers but none of the actual information in the table that pertains to the corresponding vendor.

Here is a link to an example file I'm using.

https://www.dropbox.com/s/ar9ptqxqxzr64mv/vba%20redacted.xlsx?dl=0

Here is my code:

Sub Split_Data_in_worbooks()

Application.ScreenUpdating = False

Dim data_sh As Worksheet

Set data_sh = ThisWorkbook.Sheets("Sheet1")

Dim setting_Sh As Worksheet

Set setting_Sh = ThisWorkbook.Sheets("Settings")

Dim nwb As Workbook

Dim nsh As Worksheet

''''' Get unique vendors coding below

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

data_sh.AutoFilterMode = False

data_sh.Range("D:D").Copy setting_Sh.Range("A1")

setting_Sh.Range("A:A").RemoveDuplicates 1, xlYes

Dim i As Integer

For i = 2 To Application.CountA(setting_Sh.Range("A:A"))

data\_sh.UsedRange.AutoFilter 3, 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.EntireColumn.ColumnWidth = 15

nwb.SaveAs setting\_Sh.Range("H6").Value & "/" & setting\_Sh.Range("A" & i).Value & ".xlsx"

nwb.Close False

data\_sh.AutoFilterMode = False

Next i

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

MsgBox "Done"

End Sub

Microsoft 365 and Office | Excel | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2022-04-05T19:04:44+00:00

    The vendor name is in the 4th column (column D), so you should change

    data_sh.UsedRange.AutoFilter 3, setting_Sh.Range("A" & i).Value

    to

    data_sh.UsedRange.AutoFilter 4, setting_Sh.Range("A" & i).Value

    Was this answer helpful?

    0 comments No comments