Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello from Steved
Below works as it should. Our IT section made changes, hence I need to ask your help please. At the moment it looks in Col A and uses the first numeric say 1, it moves all data associated with 1 to sheet1 which it created 2 to Sheet2 and so on. Ok I am not a code specialist so I require your help. Ok I will present 2 situations 1, Can the below be change to pickup the first 2 Char ie Sh, Sw which stands for "Shore", "Swanson" 2, I have cities City, Roskill, Papakura, Wiri, Shore, Orewa, Swanson, Waiheke. Can this be done with the below please. Thankyou. Option Explicit Public Sub CopyRowsToSheetN() 'copies rows of data from sheet named 'Data' to sheet 'named 'Sheetn' where n is the first character of the text 'in the first cell if any. Creates Sheetn if necessary. Application.ScreenUpdating = False Dim cell As Range Dim rng As Range, oldSelection As Range Dim wks As Worksheet, wksT As Worksheet Set oldSelection = Selection Set wks = ThisWorkbook.Worksheets("Data") Set rng = Intersect(wks.Columns("A"), wks.UsedRange) 'copies the row to the new sheet at the current row For Each cell In rng.Cells If Len(cell.Text) 0 Then Set wksT = GetWorksheet(wks.Parent, "Sheet" & Left (cell.Text, 1)) cell.EntireRow.Copy wksT.Columns("A").Cells(cell.Row) End If Next cell 'compresses each list to the top On Error Resume Next For Each wksT In wks.Parent.Worksheets wksT.Columns("A").SpecialCells (xlCellTypeBlanks).EntireRow.Delete xlUp Next Application.Goto oldSelection Application.ScreenUpdating = True End Sub Private Function GetWorksheet(wkbW As Workbook, _ strName As String) As Worksheet 'Returns the wkbW worksheet named. 'Adds it, if it doesn't exist. Dim wks As Worksheet On Error Resume Next Set wks = wkbW.Worksheets(strName) On Error GoTo 0 If (wks Is Nothing) Then Set wks = wkbW.Worksheets.Add(After:=Worksheets ("Data")) wks.Name = strName End If Set GetWorksheet = wks Set wks = Nothing End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I change my column designator from Numeric to Alpha? | Setting up and Configuration of Excel | |||
How do I change numeric column designations to alpha? | Excel Discussion (Misc queries) | |||
How can I change my column references from Alpha to Numeric? | Excel Worksheet Functions | |||
HOW DO I CHANGE COLUMNS FROM NUMERIC TO ALPHA HEADINGS? | Excel Discussion (Misc queries) | |||
Columns are now numeric, not alpha. how to change back? | Excel Discussion (Misc queries) |