Hi everybody, <o
></o
>
Hope that one can help with my silly problem. <o
></o
>
As a part of a big process I'm working on, I need a macro that evaluatesconditions and populate cells accordingly. The task seems to be straightforward, but something goes wrong.
I use the code below.


Hope that one can help with my silly problem. <o


As a part of a big process I'm working on, I need a macro that evaluatesconditions and populate cells accordingly. The task seems to be straightforward, but something goes wrong.
I use the code below.
Code:
[CODE]Dim rng As Range
For Each rng In Sheets("B").Range("C2:AK366")
For y = 2 To 6
If Cells(rng.Row, 1) >= Sheets("DB").Cells(y, 5) And Cells(rng.Row, 1) <= Sheets("DB").Cells(y, 6) _
And Cells(1, rng.Column).Value >= Sheets("DB").Cells(y, 7) And Cells(1, rng.Column).Value <= Sheets("DB").Cells(y, 8) _
And Cells(rng.Row, 2).Value < Sheets("DB").Cells(y, 9) Then
rng.Value = Sheets("DB").Range("K" & y).Value
End If
Next y
If IsEmpty(rng) Then
rng.Value = Sheets("DB").Range("K7")
End If
Next rng
Code:
[/COLOR][/SIZE]Below is output and layout samples [HTML]
Start, day End Day Start, time incl End, time incl Day END 01/11/2014 28/02/2015 33 40 6 01/06/2014 31/08/2014 15 40 6 01/10/2014 28/02/2015 15 32 6 01/04/2014 31/03/2015 15 40 6 01/04/2014 31/03/2015 1 14 8 1 48 8 [/HTML] [HTML]
Day 1 01/04/2014 2 02/04/2014 3 03/04/2014 4 04/04/2014 5 [/HTML]
[/FONT][FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Franklin Gothic Book][SIZE=3][COLOR=#000000]The code basically works (no error's messages), but it returns wrong values for some days . It’s definitely not a problem withdate formatting: it was tested and ruled out. [/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Franklin Gothic Book][SIZE=3][COLOR=#000000]It seems to me that at some stage the code failed torecognise conditions, particularly with values in columns . [/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]<o:p>[FONT=Franklin Gothic Book][SIZE=3][COLOR=#000000] [/COLOR][/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Franklin Gothic Book][SIZE=3][COLOR=#000000]It would be really appreciated if you give some ideas how tomodify the code to prevent overwriting (?) . If there are other possible solutions, they are welcomed [/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Franklin Gothic Book][SIZE=3][COLOR=#000000] <o:p></o:p>[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]<o:p>[FONT=Franklin Gothic Book][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]</o:p>
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][SIZE=3][COLOR=#000000][FONT=Franklin Gothic Book]Excel formula withnested if statements returns right values, but R1C1 references are not an option– all ranges must remain variables and can’t be predefined, not mention that to get results I'd need to redefine 100+ formulas. Thank you[/FONT][/COLOR][/SIZE]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]