PC Review


Reply
 
 
Gijs Breedveld
Guest
Posts: n/a
 
      2nd Mar 2008
How can I change the column charater in a loop for the following:

If iKN = 1 Then Set CellRangePMR = Worksheets("PM").Range("C6:c" & PMR + 5)
If iKN = 2 Then Set CellRangePMR = Worksheets("PM").Range("d6:d" & PMR + 5)
If iKN = 3 Then Set CellRangePMR = Worksheets("PM").Range("e6:e" & PMR + 5)
If iKN = 4 Then Set CellRangePMR = Worksheets("PM").Range("f6:f" & PMR + 5)
If iKN = 5 Then Set CellRangePMR = Worksheets("PM").Range("g6:g" & PMR + 5)
If iKN = 6 Then Set CellRangePMR = Worksheets("PM").Range("h6:h" & PMR + 5)

Best regards,

Gijs
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Mar 2008
Dim CellRangePMR As Range
Dim iKN As Long
Dim PMR As Long

'testing purposes
iKN = 1
PMR = 8

Set CellRangePMR = Nothing
Select Case iKN
Case Is = 1, 2, 3, 4, 5, 6
With Worksheets("PM")
Set CellRangePMR = .Range(.Cells(6, 2 + iKN), .Cells(PMR + 5, 2 + iKN))
'or
Set CellRangePMR = .Cells(6, 2 + iKN).Resize(PMR + 5 - 6 + 1, 1)
'or doing the arithmetic
Set CellRangePMR = .Cells(6, 2 + iKN).Resize(PMR, 1)
End With
End Select

If CellRangePMR Is Nothing Then
MsgBox "oh, oh"
Else
MsgBox CellRangePMR.Address(0, 0)
End If
Gijs Breedveld wrote:
>
> How can I change the column charater in a loop for the following:
>
> If iKN = 1 Then Set CellRangePMR = Worksheets("PM").Range("C6:c" & PMR + 5)
> If iKN = 2 Then Set CellRangePMR = Worksheets("PM").Range("d6:d" & PMR + 5)
> If iKN = 3 Then Set CellRangePMR = Worksheets("PM").Range("e6:e" & PMR + 5)
> If iKN = 4 Then Set CellRangePMR = Worksheets("PM").Range("f6:f" & PMR + 5)
> If iKN = 5 Then Set CellRangePMR = Worksheets("PM").Range("g6:g" & PMR + 5)
> If iKN = 6 Then Set CellRangePMR = Worksheets("PM").Range("h6:h" & PMR + 5)
>
> Best regards,
>
> Gijs


--

Dave Peterson
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      2nd Mar 2008
These statements replace the 6 If-Then statements you posted....

If iKN > 0 And iKN < 7 Then
Set CellRangePMR = Worksheets("PM").Range(Chr(66 + iKN) & _
"6:" & Chr(66 + iKNX) & CStr(PMR + 5))
End If

If the only values for iKN are 1 through 6 (for example, if they are being
generated by a loop counter), then you don't need the If-Then or End If
statements.

Rick


"Gijs Breedveld" <(E-Mail Removed)> wrote in message
news:1A3E92FA-0B05-41DB-8672-(E-Mail Removed)...
> How can I change the column charater in a loop for the following:
>
> If iKN = 1 Then Set CellRangePMR = Worksheets("PM").Range("C6:c" & PMR +
> 5)
> If iKN = 2 Then Set CellRangePMR = Worksheets("PM").Range("d6:d" & PMR +
> 5)
> If iKN = 3 Then Set CellRangePMR = Worksheets("PM").Range("e6:e" & PMR +
> 5)
> If iKN = 4 Then Set CellRangePMR = Worksheets("PM").Range("f6:f" & PMR +
> 5)
> If iKN = 5 Then Set CellRangePMR = Worksheets("PM").Range("g6:g" & PMR +
> 5)
> If iKN = 6 Then Set CellRangePMR = Worksheets("PM").Range("h6:h" & PMR +
> 5)
>
> Best regards,
>
> Gijs


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      3rd Mar 2008
My side comment about the iKN values being generated by a loop counter is
misleading. What I meant to say...

For any given value of iKN, the single Set statement will generate the
correct cell range to be assigned to CellRangePMR... the If-Then "housing"
is there just to make sure the value of iKN is in range. If your method of
assigning a value to iKN is such that you will always know it is in range,
then you don't have to check for that with the If-Then statement I
provided... just use the single-line Set statement and you are done.

Rick


"Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> These statements replace the 6 If-Then statements you posted....
>
> If iKN > 0 And iKN < 7 Then
> Set CellRangePMR = Worksheets("PM").Range(Chr(66 + iKN) & _
> "6:" & Chr(66 + iKNX) & CStr(PMR + 5))
> End If
>
> If the only values for iKN are 1 through 6 (for example, if they are being
> generated by a loop counter), then you don't need the If-Then or End If
> statements.
>
> Rick
>
>
> "Gijs Breedveld" <(E-Mail Removed)> wrote in
> message news:1A3E92FA-0B05-41DB-8672-(E-Mail Removed)...
>> How can I change the column charater in a loop for the following:
>>
>> If iKN = 1 Then Set CellRangePMR = Worksheets("PM").Range("C6:c" & PMR +
>> 5)
>> If iKN = 2 Then Set CellRangePMR = Worksheets("PM").Range("d6:d" & PMR +
>> 5)
>> If iKN = 3 Then Set CellRangePMR = Worksheets("PM").Range("e6:e" & PMR +
>> 5)
>> If iKN = 4 Then Set CellRangePMR = Worksheets("PM").Range("f6:f" & PMR +
>> 5)
>> If iKN = 5 Then Set CellRangePMR = Worksheets("PM").Range("g6:g" & PMR +
>> 5)
>> If iKN = 6 Then Set CellRangePMR = Worksheets("PM").Range("h6:h" & PMR +
>> 5)
>>
>> Best regards,
>>
>> Gijs

>


 
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
Loop Column =?Utf-8?B?TGlzYQ==?= Microsoft Excel Misc 2 17th Jul 2007 06:14 PM
Loop Thru Values in a Column =?Utf-8?B?Um9iZXJ0?= Microsoft Excel Programming 8 14th Feb 2007 02:14 AM
Loop through column headers to search from column name and get cell range Pie Microsoft Excel Programming 9 29th Dec 2005 12:17 AM
loop through column to find value =?Utf-8?B?Z2FiYQ==?= Microsoft Excel Programming 4 4th Nov 2004 02:29 AM
HOW-TO? Loop through cells in a column Mr. Clean Microsoft Excel Programming 4 12th Dec 2003 08:28 PM


Features
 

Advertising
 

Newsgroups
 


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