sujittalukde
05-07-2008, 04:08 AM
I am using the following code to take the value in a variable and put information by looping.
But there is certain some problems in looping so I am not getting the desired result.
Can someone please help me to rectify the code.
Also please note that I cant use formula as this is a part of my project where code has to do the job.
Sub nameandackn()
Dim Fname As Boolean
Fname = False
qtr = 1
For i = 1 To 9
Range("a" & i).Select
'Do
ename = Range("A" & (10 + qtr)).Value
If ActiveCell.Value = ename And ActiveCell.Offset(0, 2).Value = qtr Then
ackn = ActiveCell.Offset(0, 3).Value
Range("C" & (10 + qtr)).Value = ackn
Else
Do
ActiveCell.Offset(1, 0).Select
Loop Until (ActiveCell.Offset(1, 0).Value = ename And ActiveCell.Offset(0, 2).Value) Or ActiveCell.Offset(1, 0).Value = ""
ackn = ActiveCell.Offset(0, 3).Value
Range("C" & (10 + qtr)).Value = ackn
End If
qtr = qtr + 1
'Loop Until ActiveCell.Offset(1, 0).Value = "" Or Fname = True
Next i
End Sub
Edited by Simon Lloyd: Replaced Code tags with VBA tags
A sample file is attached for ready reference.
But there is certain some problems in looping so I am not getting the desired result.
Can someone please help me to rectify the code.
Also please note that I cant use formula as this is a part of my project where code has to do the job.
Sub nameandackn()
Dim Fname As Boolean
Fname = False
qtr = 1
For i = 1 To 9
Range("a" & i).Select
'Do
ename = Range("A" & (10 + qtr)).Value
If ActiveCell.Value = ename And ActiveCell.Offset(0, 2).Value = qtr Then
ackn = ActiveCell.Offset(0, 3).Value
Range("C" & (10 + qtr)).Value = ackn
Else
Do
ActiveCell.Offset(1, 0).Select
Loop Until (ActiveCell.Offset(1, 0).Value = ename And ActiveCell.Offset(0, 2).Value) Or ActiveCell.Offset(1, 0).Value = ""
ackn = ActiveCell.Offset(0, 3).Value
Range("C" & (10 + qtr)).Value = ackn
End If
qtr = qtr + 1
'Loop Until ActiveCell.Offset(1, 0).Value = "" Or Fname = True
Next i
End Sub
Edited by Simon Lloyd: Replaced Code tags with VBA tags
A sample file is attached for ready reference.