Hello All....
My requirement was to fetch few records from an excel sheet based on some criteria. Because this is the first time i have got an assignment where i have to learn VBA, i wrote a simple code to fetch data based on just one criteria (i'll include the other fields and checks later).
My logic works but the problem is that the results are displayed in the immediate window and i have to populate those results in an excel sheet. Is there any way by which i can these values in the excel sheet at desired locations.
Here's the sample code:
Private Sub GetSuccessors_Click()
Dim i, i1, i2 As Long
i = Cells(9, 12).Value
i1 = Cells(11, 10).Value
Debug.Print i1
For i2 = i To i + 2
If Range("D" & i2) <= i1 Then
Debug.Print i2
Debug.Print Range("A" & i2)
Debug.Print Range("B" & i2)
Debug.Print Range("C" & i2)
Debug.Print Range("D" & i2)
Debug.Print Range("E" & i2)
End If
Next
End Sub
My requirement was to fetch few records from an excel sheet based on some criteria. Because this is the first time i have got an assignment where i have to learn VBA, i wrote a simple code to fetch data based on just one criteria (i'll include the other fields and checks later).
My logic works but the problem is that the results are displayed in the immediate window and i have to populate those results in an excel sheet. Is there any way by which i can these values in the excel sheet at desired locations.
Here's the sample code:
Private Sub GetSuccessors_Click()
Dim i, i1, i2 As Long
i = Cells(9, 12).Value
i1 = Cells(11, 10).Value
Debug.Print i1
For i2 = i To i + 2
If Range("D" & i2) <= i1 Then
Debug.Print i2
Debug.Print Range("A" & i2)
Debug.Print Range("B" & i2)
Debug.Print Range("C" & i2)
Debug.Print Range("D" & i2)
Debug.Print Range("E" & i2)
End If
Next
End Sub