LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Clean this select case code up a bit.

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I get =Clean and =Proper Case to run on all cells in a col George Excel Worksheet Functions 0 February 3rd 10 07:41 PM
Code not working, copy in Select Case section not copying over. DanielleVBANewbie Excel Programming 10 July 22nd 08 06:44 PM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Simplify Code - Select Case Edgar Thoemmes[_4_] Excel Programming 1 January 19th 05 01:32 AM


All times are GMT +1. The time now is 01:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"