Hi all, I need help with vba, I want to make vba to:
Everytime I run it, my excel and vba always not responding, but If I try only with sheet1 it works fine..
This what I make:
- Search day and month from 4 sheet: Sheet1, Sheet2, Sheet3, Sheet4 from 1 January to 31 December
- There's priority sheet sequence sheet1 ->sheet2 -> sheet3 -> sheet4, it can't be mix or the calculation will all wrong
- So if it at 1 January the sheet1 will calculate some formula, and then I can calculate sheet2, then sheet3 and then sheet4
- If it finish in sheet4, move the search to 2 January, and so on..
Everytime I run it, my excel and vba always not responding, but If I try only with sheet1 it works fine..
This what I make:
Code:
Sub LookingFor()
Dim i As Integer, j As Integer
Dim rcell1 As Range, rcell2 As Range, rcell3 As Range, rcell4 As Range
Dim rng1 As Range, rng2 As Range, rng3 As Range, rng4 As Range
Set rng1 = Sheets("Sheet1").Range("C3:C700")
Set rng2 = Sheets("Sheet2").Range("C3:C700")
Set rng3 = Sheets("Sheet3").Range("C3:C700")
Set rng4 = Sheets("Sheet4").Range("C3:C700")
For i = 1 To 12 'For month'
For j = 1 To 31 'For day'
For Each rcell1 In rng1
If Day(rcell1.Value) = i And Month(rcell1.Value) = j Then
'Do something'
End If
'---------------------------------------------------------------------------------------------------------------------------------------'
[INDENT] For Each rcell2 In rng2[/INDENT]
[INDENT] If Day(rcell2.Value) = i And Month(rcell2.Value) = j Then[/INDENT]
[INDENT] 'Do Something'[/INDENT]
[INDENT] End If[/INDENT]
'---------------------------------------------------------------------------------------------------------------------------------------'
[INDENT=2] For Each rcell3 In rng3[/INDENT]
[INDENT=2] If Day(rcell3.Value) = i And Month(rcell3.Value) = j Then[/INDENT]
[INDENT=2] 'Do Something'[/INDENT]
[INDENT=2] End If[/INDENT]
'---------------------------------------------------------------------------------------------------------------------------------------'
[INDENT=3] For Each rcell4 In rng4[/INDENT]
[INDENT=3] If Day(rcell4.Value) = i And Month(rcell4.Value) = j Then[/INDENT]
[INDENT=3] 'Do something'[/INDENT]
[INDENT=3] End If[/INDENT]
Next
Next
Next
Next
Next
Next
End Sub