PC Review


Reply
Thread Tools Rate Thread

column letters and numbers

 
 
Matt S
Guest
Posts: n/a
 
      23rd Mar 2009
All,

Can someone please optimize this code?

If UBound(arrLeanConc) = 1 Then
strdummy = "A"
ElseIf UBound(arrLeanConc) = 2 Then
strdummy = "B"
ElseIf UBound(arrLeanConc) = 3 Then
strdummy = "C"
ElseIf UBound(arrLeanConc) = 4 Then
strdummy = "D"
Else
End If

ActiveCell.Offset(12, 2).Range("A1:" & strdummy & LastRow - 12).Value =
Application.Transpose(arrLeanConc)


my upperbound on the array arrLeanConc changes based on the number of Lean
gases I have specified. I also have to use the reference style and not
absolute. I would like to post the results of the arrLeanConc in my excel
file. There must be a better way to do this.

Any help would be appreciated!
Thanks!
Matt S
 
Reply With Quote
 
 
 
 
joel
Guest
Posts: n/a
 
      23rd Mar 2009
Hre are a few improvements. When using nummerical columns use CELLS instead
of RANGE.

'refinement 1
ActiveCell.Offset(12, 2).Range(Range("A1"), Cells(LastRow - 12),
UBound(arrLeanConc)).Value = _
Application.Transpose(arrLeanConc)

'refinement 2
Range(Range("A1"), Cells(LastRow - 12), UBound(arrLeanConc)).Offset(12,
2).Value = _
Application.Transpose(arrLeanConc)

'refinement 3
RowOff = 12
ColOff = 2
Range(Cells(1 + RowOff, 1 + ColOff), Cells(LastRow), UBound(arrLeanConc) +
ColOff).Value = _
Application.Transpose(arrLeanConc)


"Matt S" wrote:

> All,
>
> Can someone please optimize this code?
>
> If UBound(arrLeanConc) = 1 Then
> strdummy = "A"
> ElseIf UBound(arrLeanConc) = 2 Then
> strdummy = "B"
> ElseIf UBound(arrLeanConc) = 3 Then
> strdummy = "C"
> ElseIf UBound(arrLeanConc) = 4 Then
> strdummy = "D"
> Else
> End If
>
> ActiveCell.Offset(12, 2).Range("A1:" & strdummy & LastRow - 12).Value =
> Application.Transpose(arrLeanConc)
>
>
> my upperbound on the array arrLeanConc changes based on the number of Lean
> gases I have specified. I also have to use the reference style and not
> absolute. I would like to post the results of the arrLeanConc in my excel
> file. There must be a better way to do this.
>
> Any help would be appreciated!
> Thanks!
> Matt S

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      23rd Mar 2009
Hi Matt, You haven't given us a whole lot to work with but if i understand
your problem correctly a For...Next loop will do the trick

For i = 0 To UBound(ArrLeanConc)
ActiveSheet.Cells(1, i).Value = ArrLeanConc(i)
Next

In place of

ActiveCell.Offset(12, 2).Range("A1:" & strdummy & LastRow - 12).Value =
Application.Transpose(arrLeanConc)

"Matt S" wrote:

> All,
>
> Can someone please optimize this code?
>
> If UBound(arrLeanConc) = 1 Then
> strdummy = "A"
> ElseIf UBound(arrLeanConc) = 2 Then
> strdummy = "B"
> ElseIf UBound(arrLeanConc) = 3 Then
> strdummy = "C"
> ElseIf UBound(arrLeanConc) = 4 Then
> strdummy = "D"
> Else
> End If
>
> ActiveCell.Offset(12, 2).Range("A1:" & strdummy & LastRow - 12).Value =
> Application.Transpose(arrLeanConc)
>
>
> my upperbound on the array arrLeanConc changes based on the number of Lean
> gases I have specified. I also have to use the reference style and not
> absolute. I would like to post the results of the arrLeanConc in my excel
> file. There must be a better way to do this.
>
> Any help would be appreciated!
> Thanks!
> Matt S

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      23rd Mar 2009
You can replace all of your If..Then..Else blocks with one of these single
lines of code depending on one condition.

If the UBound of your arrLeanConc is never going to be greater than 26....

strdummy = Chr(64 + UBound(arrLeanConc))

Otherwise...

strdummy = Split(Cells(1, UBound(arrLeanConc)).Address(, 0), "$")(0)

If the only place you are using the strdummy variable is in the one line you
showed us, then you can eliminate the strdummy variable and just use its
equivalent (the right side of the appropriate statement above) directly in
the line in place of the strdummy variable.

--
Rick (MVP - Excel)


"Matt S" <Matt (E-Mail Removed)> wrote in message
news:18611586-4D05-408C-9082-(E-Mail Removed)...
> All,
>
> Can someone please optimize this code?
>
> If UBound(arrLeanConc) = 1 Then
> strdummy = "A"
> ElseIf UBound(arrLeanConc) = 2 Then
> strdummy = "B"
> ElseIf UBound(arrLeanConc) = 3 Then
> strdummy = "C"
> ElseIf UBound(arrLeanConc) = 4 Then
> strdummy = "D"
> Else
> End If
>
> ActiveCell.Offset(12, 2).Range("A1:" & strdummy & LastRow - 12).Value =
> Application.Transpose(arrLeanConc)
>
>
> my upperbound on the array arrLeanConc changes based on the number of Lean
> gases I have specified. I also have to use the reference style and not
> absolute. I would like to post the results of the arrLeanConc in my excel
> file. There must be a better way to do this.
>
> Any help would be appreciated!
> Thanks!
> Matt S


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I change column numbers back to column letters? =?Utf-8?B?U3BhY2UgRWxm?= Microsoft Excel Worksheet Functions 3 2nd Mar 2006 09:35 PM
Covert Column Numbers to Column Letters in Excel VB =?Utf-8?B?S2VpdGg=?= Microsoft Excel Programming 12 17th Mar 2005 10:21 PM
row numbers & column letters =?Utf-8?B?QUxPbHNvbjIx?= Microsoft Excel Misc 3 10th Dec 2004 05:45 PM
Column numbers to letters Martha Microsoft Excel Misc 3 20th Aug 2004 07:19 PM
Re: column numbers instead of letters Dave Peterson Microsoft Excel Setup 0 9th Aug 2003 04:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:41 AM.