VBA If Functions and Copying Rows over to new sheets

grannybrad

New Member
Joined
Jun 26, 2013
Messages
2
Hi, I'm having trouble coming up with a way to create a code in VBA that would parse through a table of data, recognize if a value was in between a set of numbers and if it was, copy and paste the row into the next avaiable empty row in the new sheet. Then, if all went well, it would go down to the next value

For reference:

All values in column I are between 3-30

If the value in column I< 5, then I would want to the entire row containing that value to copy to the next empty row in sheet 3-5yr Mat.

if 5< i < 7, then 5-7yr Mat.

if 7<i<10, then 7-10yr Mat.

if 10<i<18, then 10-18ys Mat.

if 18<i, then 18-30yr Mat.

<I, Mat.

Any tips on how to set up that code?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,

Does these code snippets help?
Code:
    'Determine destination sheetname
    If I > 5 And I < 7 Then ShtName = "3-5yr Mat."
    If I = 7 Then ShtName = "7yr Mat."
    
    'Find it's last used row
    LastRowUsed = Sheets(SntName).UsedRange.Rows.Count
    
    'Copy current row to next empty row on destination sheet
    Rows(R).Select
    Selection.Copy
    Sheets(ShtName).Select
    Rows(LastRowUsed + 1).Select
    ActiveSheet.Paste

    'Return to my sheet and go to next row
    Sheets("..").Activate
    R = R + 1
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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