Populate VBA immediate window data in a Worksheet

mayank_11

New Member
Joined
May 22, 2018
Messages
3
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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Welcome to the Board!

You can do what you want pretty easily. You just need to determine where you want to put it, i.e.
if you wanted to put them in similar cells on sheet 2 (assuming you are starting on sheet 1), you could simply do:
Code:
Sheets("Sheet2").Range("A" & i2) = Sheets("Sheet1").Range("A" & i2)
 
Upvote 0
Thanks for your reply!!
i tried this code, works fine but the data is populated in the same columns and rows as the source sheet. I have to paste the data in a defined set of rows and columns ( kind of an output table that i have created).

So, if i get (n) number of records satisfying my criteria they should be populated in that output table.
 
Upvote 0
i tried this code, works fine but the data is populated in the same columns and rows as the source sheet.
That was just an example to show you what code that did something like that would look like.

I have to paste the data in a defined set of rows and columns ( kind of an output table that i have created).

So, if i get (n) number of records satisfying my criteria they should be populated in that output table.
If you want help with this part, you need to provide very SPECIFIC detail, such as the ranges where you want this populated.
Otherwise, we are left to make assumptions again, and we are back to where I was with my initial reply.
 
Upvote 0

Forum statistics

Threads
1,215,393
Messages
6,124,680
Members
449,180
Latest member
kfhw720

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