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

On Sunday, June 23, 2013 12:36:36 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Sat, 22 Jun 2013 23:04:51 -0700 (PDT) schrieb Howard:



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)




try:



Sub A_B_C_Sheet()

Dim jName As String

Dim StRow As Integer

Dim myCol As Long



With Sheets("Sheet1")

jName = .Range("J20")



Select Case jName

Case "alpha"

StRow = 10

Case "bravo"

StRow = 11

Case "charlie"

StRow = 12

Case Else

MsgBox "NaDa Good jName"

End Select

myCol = .Cells(StRow, .Columns.Count).End(xlToLeft).Column - 2

.Range("B" & StRow).Offset(0, 1).Resize(1, myCol).Copy _

Sheets(jName).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)

End With

End Sub





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Now that is clean, & nice!

Thanks Claus.
Reply
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 02:18 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"