VBA: Searching For Value in Column & Copy Row

PB7

Board Regular
Joined
Mar 1, 2011
Messages
58
Hello,

All I need to do in Excel VBA is:

- probably using For / Next and the If / Then structures
- loop through a block of data, and if VBA finds a number
- then copy /paste the contents of the specific row to another area

The number would be a integer in a single given column, like for example 4, representing the 4th batch of work, that I am processing, and so on. Have dabbled in VBA, but evidently don't know enough to do this one. Many thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Texasalynn,

Ideally, if looping finds, say 9 rows among 100 rows that meet the criteria, VBA copy/pastes the data from those 9 rows into another worksheet, forming 1 contiguous new block of data. Does that help?

Houston's a very cool town. Lived there, years ago.
 
Upvote 0
sounds like if you are looking for a filter? Then you can copy the data of the filtered rows to "another area". But since you haven't given us the details of how the "filter" would be decided and where to place the data. That's all I can give until you give a little more details. :)
 
Upvote 0
Yes, now that you mention it, that's what I am doing, though I didn't think of it that way initially.

VBA in this case would be essentially filtering on a column with integers. So I recorded a macro that filters on that column, and get this.

Range("A1:B11").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$B$11").AutoFilter Field:=2, Criteria1:="4"

Now, once this is done, can I select the filter results, and copy them to another area, like another worksheet tab?

Thanks for the very nice, responsive replies.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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