Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default Recode values

Hello,

I want to recode values in a MainRange according to rules found in an
IndexTable with 3 columns : the 2 first columns delimit a range and
the 3rd one is the value to assign to the MainRange values if they
lay in that range



What would be the most efficient approach (some array function I
guess)


Thanks
Avi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Recode values

avi brought next idea :
Hello,

I want to recode values in a MainRange according to rules found in an
IndexTable with 3 columns : the 2 first columns delimit a range and
the 3rd one is the value to assign to the MainRange values if they
lay in that range



What would be the most efficient approach (some array function I
guess)


Thanks
Avi


If this is the same Q you asked in '...vb.general.discussion' then...

A1: 3,5,7
A2: 2,4,6

B1: 1; C1: 4; D1: 57
B2: 5; C2: 7; D2: 88

Option Explicit

Sub RecodeValues()
Dim vValsToRecode, vSourceArray, vTemp
Dim i As Long, j As Long, k As Long
vValsToRecode = Range("A1:A2")
vSourceArray = Range("B1:D2")
For i = LBound(vValsToRecode) To UBound(vValsToRecode)
vTemp = Split(vValsToRecode(i, 1), ",")
For j = LBound(vSourceArray) To UBound(vSourceArray)
For k = LBound(vTemp) To UBound(vTemp)
Select Case CLng(vTemp(k))
Case vSourceArray(j, 1) To vSourceArray(j, 2)
vTemp(k) = vSourceArray(j, 3)
End Select 'Case CLng(vTemp(k))
Next 'k
Next 'j
vValsToRecode(i, 1) = Join(vTemp, ",")
Next 'i
Range("A1").Resize(UBound(vValsToRecode)) = vValsToRecode
End Sub


Results:

A1: 57,88,88
A2: 57,57,88

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default Recode values

On 4 août, 22:09, GS wrote:
avi brought next idea :

Hello,


I want to recode values in a MainRange *according to rules found in an
IndexTable with 3 columns : the 2 first columns delimit a range and
the 3rd one is the value to assign to the MainRange *values *if they
lay in that range


What would be the most efficient approach (some array function I
guess)


Thanks
Avi


If this is the same Q you asked in '...vb.general.discussion' then...

A1: 3,5,7
A2: 2,4,6

B1: 1; C1: 4; D1: 57
B2: 5; C2: 7; D2: 88

Option Explicit

Sub RecodeValues()
* Dim vValsToRecode, vSourceArray, vTemp
* Dim i As Long, j As Long, k As Long
* vValsToRecode = Range("A1:A2")
* vSourceArray = Range("B1:D2")
* For i = LBound(vValsToRecode) To UBound(vValsToRecode)
* * vTemp = Split(vValsToRecode(i, 1), ",")
* * For j = LBound(vSourceArray) To UBound(vSourceArray)
* * * For k = LBound(vTemp) To UBound(vTemp)
* * * * Select Case CLng(vTemp(k))
* * * * * Case vSourceArray(j, 1) To vSourceArray(j, 2)
* * * * * * vTemp(k) = vSourceArray(j, 3)
* * * * End Select 'Case CLng(vTemp(k))
* * * Next 'k
* * Next 'j
* * vValsToRecode(i, 1) = Join(vTemp, ",")
* Next 'i
* Range("A1").Resize(UBound(vValsToRecode)) = vValsToRecode
End Sub

Results:

* A1: 57,88,88
* A2: 57,57,88

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Thanks Garry,

Is this array approach supposed to be faster than looping directly on
the cells address directly?

Avi



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Recode values

avi formulated on Wednesday :
On 4 août, 22:09, GS wrote:
avi brought next idea :

Hello,


I want to recode values in a MainRange *according to rules found in an
IndexTable with 3 columns : the 2 first columns delimit a range and
the 3rd one is the value to assign to the MainRange *values *if they
lay in that range


What would be the most efficient approach (some array function I
guess)


Thanks
Avi


If this is the same Q you asked in '...vb.general.discussion' then...

A1: 3,5,7
A2: 2,4,6

B1: 1; C1: 4; D1: 57
B2: 5; C2: 7; D2: 88

Option Explicit

Sub RecodeValues()
* Dim vValsToRecode, vSourceArray, vTemp
* Dim i As Long, j As Long, k As Long
* vValsToRecode = Range("A1:A2")
* vSourceArray = Range("B1:D2")
* For i = LBound(vValsToRecode) To UBound(vValsToRecode)
* * vTemp = Split(vValsToRecode(i, 1), ",")
* * For j = LBound(vSourceArray) To UBound(vSourceArray)
* * * For k = LBound(vTemp) To UBound(vTemp)
* * * * Select Case CLng(vTemp(k))
* * * * * Case vSourceArray(j, 1) To vSourceArray(j, 2)
* * * * * * vTemp(k) = vSourceArray(j, 3)
* * * * End Select 'Case CLng(vTemp(k))
* * * Next 'k
* * Next 'j
* * vValsToRecode(i, 1) = Join(vTemp, ",")
* Next 'i
* Range("A1").Resize(UBound(vValsToRecode)) = vValsToRecode
End Sub

Results:

* A1: 57,88,88
* A2: 57,57,88

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Thanks Garry,

Is this array approach supposed to be faster than looping directly on
the cells address directly?

Avi


You're welcome!

Looping the worksheet will always be slower whether you're reading or
writing. You can time this so you see the difference. It will be
substantial if the range is large.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
recode variable Robinb Excel Worksheet Functions 1 October 30th 09 10:13 AM
Find matching values, copy/paste values as well as values in ColA ryguy7272 Excel Programming 2 September 28th 09 06:20 AM
simple recode operation urlwolf Excel Worksheet Functions 3 March 18th 07 12:35 AM
how do I recode a likert scale merlin Excel Discussion (Misc queries) 3 September 26th 05 10:56 AM
Recode Varialbe Values Charles Excel Discussion (Misc queries) 5 December 7th 04 06:01 PM


All times are GMT +1. The time now is 09:44 PM.

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

About Us

"It's about Microsoft Excel"