Copy data to another sheet when criteria is matched

bask1022

New Member
Joined
Feb 5, 2018
Messages
12
I'm a novice to VB - I have seen several examples close to what I need, but when I try to modify them slightly I end up breaking the function because I just don't know enough of the syntax.

I need to assess data in column N of the first sheet (ToDo) starting with row 5 and going to the last row (which varies depending on the month). Any time the data in N is greater than 0, I need to copy the data in columns A and B to sheet Week1, starting in cell A16 .

Both sheets (ToDo and Week1) are in the same workbook.

Thank you in advance for your help!:)
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
something along the lines of

Dim c As Range, rng
Dim lr As Long
Dim col_a_val As String
Dim col_b_val As String


Sheets("ToDo").Activate

lr = Range("n" & Rows.Count).End(xlUp).Row
Set rng = Range("n5:n" & lr)
For Each c In rng
If c.Value > 0 Then
col_a_val = c.Offset(0, -13).Value
col_b_val = c.Offset(0, -12).Value
Sheets("Week1").Activate
lr = Range("a" & Rows.Count).End(xlUp).Row + 1
Range("a" & lr) = col_a_val
Range("b" & lr) = col_b_val
Sheets("ToDo").Activate
End If
Next c
 
Upvote 0
SteveO59L - thank you so much for responding.....

I pasted your code into the spreadsheet, and when I try to run it I get a "Invalid outside procedure" error on the line

Sheets("ToDo").Activate

What have I done wrong? Thanks...


something along the lines of

Dim c As Range, rng
Dim lr As Long
Dim col_a_val As String
Dim col_b_val As String


Sheets("ToDo").Activate

lr = Range("n" & Rows.Count).End(xlUp).Row
Set rng = Range("n5:n" & lr)
For Each c In rng
If c.Value > 0 Then
col_a_val = c.Offset(0, -13).Value
col_b_val = c.Offset(0, -12).Value
Sheets("Week1").Activate
lr = Range("a" & Rows.Count).End(xlUp).Row + 1
Range("a" & lr) = col_a_val
Range("b" & lr) = col_b_val
Sheets("ToDo").Activate
End If
Next c
 
Upvote 0
I did receive the file - was just out sick for a few days. Thank you - it worked well! Just one question:

I tried to modify the macro to display columns E and N instead of A and B, and though the macro ran, there was no visible data displayed. Might it be because the data in columns E and N is calculated via a formula instead of typed in directly?

Thank you again for your help and patience....
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,628
Members
452,661
Latest member
Nonhle

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