Question on modifying a Macro..........

sssb2000

Well-known Member
Joined
Aug 17, 2004
Messages
1,169
hi,
i have the following code for doing a procedure......i was hoping i could ask for a little help regarding modifying it a little....

First to tell you what the code does......
Right now, it searches through column AA; searches for the lowest number; if it finds the cell with the lowest value in AA, it then adds a 1 to the row to the left of it....the code then subtracts 1 from G39 and does the same process again.....until G39 has a value of zero

Now the problem is that before, i used to have the sections in AA merged....so what you had was ONE 131, ONE 26 and ONE 139
Now what i've done is that i've expanded those merged cells and so now 131 shows on every cell whithin that section (note that in the example i'm posting, i have 3 sections.....each section has the same number)

How do i modify this code so that it searches AA but considers 131 only once as oppose to considering it as many rows as there are?
non-Working v7 1-28-05.xls
ZAAABAC
1372
1373131
1374131
1375131
1376131
1377131
1378131
1379131
1380131
1381131
1382131
1383
138436
138536
138636
138736
138836
138936
139036
139136
1392
1393139
1394139
1395139
1396139
1397139
1398139
Sheet1




Code:
Sub evenout(rngaddone As Range)
Dim rng As Range, x&, cell As Range

'***************************************************
'ADDONE IS THE RANGE IN COLUMN AA
Set addone = rngaddone.Offset(0, 17).Cells(1)
'MsgBox Range((addone.Address)).Value
'Exit Sub
'***************************************************

If Not IsNumeric([G39]) Or [G39] = 0 Or Len([G39]) = 0 Then Exit Sub
Set rng = Range([AA1], [AA65536].End(xlUp))
 
If [G39] > Application.WorksheetFunction.Count(rng) Then
    For Each cell In rng
        
        If IsNumeric(cell) And Len(cell)<> 0 Then
            [G39] = [G39] - 1
            cell.Offset(0, -1) = cell.Offset(0, -1) + 1
        End If
    Next
Else
    x = Application.WorksheetFunction.Small([aa:aa], [G39])
    For Each cell In rng
        If IsNumeric(cell) And Len(cell)<> 0 And cell<= x Then
            [G39] = [G39] - 1
            cell.Offset(0, -1) = cell.Offset(0, -1) + 1
            If [G39] = 0 Then Exit For
        End If
    Next
End If


End Sub
 
still the same problem...hehe

i'm sorry....
i put a 1 in G39 so that it would search for the lowest number and just do this proceess once....

i had something like this:

4
4
4

6
6
6

7
7

4
4

and it added 1 to the offset(-1) of ALL 4's! when it should have only added the 1 for the first 3 fours....cause the other 2 fours are in a different section...

do you know what i mean?
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Isn't that what you said you wanted?

see, if 4 is the lowest number in a section in AA, 1 can be added to Z....and 1 unit should be subtracted from G39
if there is another section with the number 4 which becomes the lowest number next, then another 1 should be subtracted from G39

So, do you want to find the first occurrence of the lowest number and ignore other sets of the same number or include them? The way the macro is currently written, it will put a 1 next to in this example of all 4s by set, and is deducting 1 from G39 for each set of 4s.
 
Upvote 0
ok....i can see that i didn't communicate well enough. i appologize for any confussion.

what i was trying to say is that AA is defined by different sections...(hence the space between the rows)
what the code should do, is search AA if there are 10 different sections let say....and all have 4's.....(what i mean is a series of 4's then some other number, then 4's again, and so on...)...then the code should deduct 10 from G39....not just 1

point being that there are different sections in AA sperated by other numbers....and the code needs to distinguish between the different sections...and treat each section as just another number! so if it adds 1 to the first set of 4's and subtracts 1 from G39, it would need to do the same thing for the next set of 4's!



;)
 
Upvote 0
if i have the following....and i put a 1 in G39 (meaning that 1 can be distributed only ONCE)....
non-Working v7 2-1-05.xls
ZAAABAC
44
54
64
7
86
96
106
11
127
137
147
15
164
174
184
194
204
21
229
239
249
Sheet2







i get this:
non-Working v7 2-1-05.xls
ZAAABAC
414
514
614
7
86
96
106
11
127
137
147
15
1614
1714
1814
1914
2014
21
229
239
249
25
Sheet2



notice that only the first set of 4's "Should" have gotten a 1 in column Z
 
Upvote 0
Using your samples, this is the result of 1 in G39.
addaa.xls
ZAAABAC
96414
96514
96614
96714
96814
969
9706
9716
9726
9736
974
9757
9767
9777
978
9794
9804
9814
9824
9834
984
9859
9869
9879
Sheet1


This is the result of 2 in G39:
addaa.xls
ZAAABAC
96414
96514
96614
96714
96814
969
9706
9716
9726
9736
974
9757
9767
9777
978
97914
98014
98114
98214
98314
984
9859
9869
9879
Sheet1


And the result of 3 in G39:
addaa.xls
ZAAABAC
96414
96514
96614
96714
96814
969
97016
97116
97216
97316
974
9757
9767
9777
978
97914
98014
98114
98214
98314
984
9859
9869
9879
Sheet1


Can you please explain what of this is not correct?
 
Upvote 0
THAT IS ABSOLUTELY CORRECT! i don't understand! how come i'm not getting that?
did ANYTHING change in your code?
 
Upvote 0
Not since the last version I posted.

There are blank cells between the sets of numbers like in the samples, right?
 
Upvote 0
that's correct.
:(
i don't get it! what you have in your example is EXACTLY what i need. EXACTLY!
 
Upvote 0
HOTPEPER!!!!!!!!!!!!!!!!!!!!
IT WORKED!!!!!!!!!!!!!!!!!!

oh my God....you are soooo awesome! you are the best!
thank you SOOOO much for ALL of your help! you are Awesome! :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top