Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This works okay as is, but me thinks it could be a bit "cleaner".
How could I replace aCol, bCol & cCol with a single xCol that would pertain to whatever case is selected and resize to the last column of data in the row for that selection? As you can see I am referring to B10:B12 (could be more later) and have to do a - 2 because of the offset and the column is B. (I guess I could ignore the - 2and copy empty cells to the other sheets but that seems clunky) Thanks, Howard Sub A_B_C_Sheet() Dim jName As String Dim aCol As Long, bCol As Long, cCol As Long jName = Range("J20") With ActiveSheet aCol = .Cells(10, .Columns.Count).End(xlToLeft).Column - 2 bCol = .Cells(11, .Columns.Count).End(xlToLeft).Column - 2 cCol = .Cells(12, .Columns.Count).End(xlToLeft).Column - 2 Select Case jName Case "alpha" Sheets("Sheet1").Range("B10").Offset(0, 1).Resize(1, aCol).Copy _ Sheets("alpha").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) Case "bravo" Sheets("Sheet1").Range("B11").Offset(0, 1).Resize(1, bCol).Copy _ Sheets("bravo").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) Case "charlie" Sheets("Sheet1").Range("B12").Offset(0, 1).Resize(1, cCol).Copy _ Sheets("charlie").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) Case Else MsgBox "NaDa Good jName" End Select End With End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How can I get =Clean and =Proper Case to run on all cells in a col | Excel Worksheet Functions | |||
Code not working, copy in Select Case section not copying over. | Excel Programming | |||
Case without Select Case error problem | Excel Discussion (Misc queries) | |||
Simplify Code - Select Case | Excel Programming |