macro

Rohit Ram

New Member
Joined
Jun 1, 2009
Messages
4
I want to copy and paste on a new workbook based on dropdown list. and to name each sheet as per the list from the dropdown. and also to freeze panes from row8 for all sheets.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I do something close to this - I'm assuming you can use the validation features to create the drop lists - thus I'm including a code snipit to get you through the rest (just needs a little tweaking for your customer portion). Good luck!

Ben

' Set column w/ tab names
Public Const intTabNameCol As Integer = 1
Sub CreateNewExcelFile()
' This counts the number of rows (my list was the last list in column A - starts in row 2 - alter as needed)
Dim intCtRows As Integer
Cells(65536, intTabNameCol).Select
Selection.End(xlUp).Select
Range(Selection, "A1").Select
intCtRows = Selection.Rows.Count

' Create variables for all new tab names
Dim intLoop1, intCtLoops As Integer
ReDim strNewSheetNameArray(intCtRows) As String

For intLoop1 = 2 To intCtRows
intCtLoops = intCtLoops + 1 ' so u aren't dealing w/ variable on where this starts / stops
strNewSheetNameArray(intCtLoops) = Cells(intLoop1, intTabNameCol).Value
Next intLoop1

' Create new workbook
Dim intCtTabs, intNewSheetCtLoop1, intNewSheetCtLoop2 As Integer
Workbooks.Add

intCtTabs = ActiveWorkbook.Sheets.Count ' Number of tabs in worksheet (my default is 3)

For intNewSheetCtLoop1 = 1 To intCtLoops
intNewSheetCtLoop2 = intNewSheetCtLoop2 + 1

' Logic for assessing to few or to many sheets
If intNewSheetCtLoop2 <= intCtTabs Then
Worksheets(intNewSheetCtLoop1).Select
Worksheets(intNewSheetCtLoop1).Name = strNewSheetNameArray(intNewSheetCtLoop2)
ActiveWindow.SplitRow = 8
ActiveWindow.FreezePanes = True
End If
' Too many - delete extra
If intNewSheetCtLoop2 > intCtLoops Then
Worksheets(intNewSheetCtLoop1).Delete
End If
If intNewSheetCtLoop2 > intCtTabs Then
Sheets.Add
ActiveSheet.Select
ActiveSheet.Name = strNewSheetNameArray(intNewSheetCtLoop2)
ActiveWindow.SplitRow = 8
ActiveWindow.FreezePanes = True
Sheets(strNewSheetNameArray(intNewSheetCtLoop2)).Move After:=Sheets(strNewSheetNameArray(intNewSheetCtLoop2 - 1))
End If

Next intNewSheetCtLoop1

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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