Change macro range from column A to B

sachin483

Board Regular
Joined
Mar 31, 2015
Messages
163
Office Version
  1. 2019
Platform
  1. Windows
I want to change the column select range from A to B with top 5 rows freeze in every sheet and then split
VBA Code:
Sub sheets_seperator()
Dim flpath As String
Dim lr As Integer
Application.DisplayAlerts = False
Application.ScreenUpdating = False

cnt = 1
flpath = Application.InputBox("Enter the file location") & "\"

On Error Resume Next
On Error Resume Next
Sheets("List").Delete

Sheets.Add(After:=Sheets(Sheets.Count)).Name = "List"

Sheets("Rep_1").Select
Columns("a:a").Copy

Sheets("List").Select
Range("A1").PasteSpecial xlPasteValuesAndNumberFormats

Range("A:A").RemoveDuplicates 1, xlYes
Range("A1").Select
Range("A1:A2").EntireRow.Delete
Columns.AutoFit
ActiveSheet.UsedRange.AutoFilter 1, "*Total*"
Sheets("List").AutoFilter.Range.Offset(1).Delete xlShiftUp
ActiveSheet.ShowAllData

Set mstrwb = ThisWorkbook

lr = Sheets("List").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
Teamname = Cells(i, 1).Value

Workbooks.Add
ActiveWorkbook.SaveAs flpath & Teamname & "- Report" & ".xlsx", FileFormat:=51
Set extr = ActiveWorkbook

For Each ws In mstrwb.Worksheets
ws.Copy After:=extr.Sheets(Sheets.Count)
Next ws

Sheets("List").Delete
Sheets(1).Delete

For Each ws In extr.Sheets
ws.Select

Range("a4").Select
Rows("4:4").Select
       Selection.AutoFilter
Selection.AutoFilter 1, "<>" & "*" & Teamname & "*"

Range("a4").Select
ActiveSheet.AutoFilter.Range.Offset(1).Delete xlShiftUp
ActiveSheet.ShowAllData
Range("a5").Select
Next ws

Sheets(2).Select

ActiveWorkbook.Close True
cnt = cnt + 1
Next i
MsgBox cnt - 1 & " Files created Successfully"

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Not sure what the code is doing, but try to replace A with B within code?
Range("A1")
Range("A1:A2")
Range("A:A")
Range("A1")
columns("a:a")

to become

Range("B1")
Range("B1:B2")
Range("B:B")
Range("B1")
columns("B:B")

???
 
Upvote 0
tried but not file not splitting, the code is trying split various sheet from workbook where top 5 rows are freeze and range is column B
 
Upvote 0
I assume the Team Names are in column A of the List sheet. What column are they in, in all the other sheets ? Show us a sample including the row and column references..
 
Upvote 0
SL.DivCODDSCRCODDSCRNo.CLGSTGT
No.MSL
1AAAR00001NNNNA1B15A9400851087717213
2AAAR00001NNNNA2B21C5728650956432346
3AAAR00001NNNNA3B32A6346872462689320
4AAAR00001NNNNA4B41A5894303158231437
5BBAR00002BBBBB1A11A5875376658299423
6BBAR00002BBBBB2A21B5757921057497094
7BBAR00002BBBBB3A31B5731593757373917
8BBAR00002BBBBB4A46B7529024376465857

sample of sheet1 ,rows and column will be freeze
 
Upvote 0
What is the macro doing and what is it not doing ?
Is it creating the separate workbooks but not deleting the rows that don't meet the criteria ?
What CELL is SL in ?
What column are you wanting to filter on is it the "DIV" column ?
 
Upvote 0
macro is creating separate workbooks
wants to filter of div column
top 5 rows should be freeze with formatting

previously div column was in A column now i have to shifted to B so macro is not creating separate workbooks
 
Upvote 0
The Div column is clearly in Column B of the other worksheets but what column is it in on the sheets List AND Rep_1 ?
Also you didn't answer what cell the heading SL is in ?
 
Upvote 0
Div Column sheets List AND Rep_1 - column B in every sheet
cell the heading SL is in - will be column A of every sheet
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,662
Members
452,992
Latest member
TokugawaIesuma

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