Macro Novice

Mon_Star

New Member
Joined
May 12, 2016
Messages
5
Hi friends,

I am new to VBA but I find it immediately interesting! What I’m trying to do involves two worksheets. When I run the macro, I would like it to search through the worksheet “Screening Log” in column j to find all the records denoted “Y”. Making note of that row, I’d then like the macro to move across to the column C where I have stored a unique identifier for that record. I want that unique identifier pasted into the second worksheet “OT and Follow Up”.

I tried adapting some code as below, but to no avail. Basically what I want to avoid having to do is filtering the for “Y” in the first worksheet and copying them across. I’d rather make it a macro and reduce the number of steps in an already long process.

Any help?

Sub Update2()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("<wbr>Screening Log")
Set Target = ActiveWorkbook.Worksheets("OT and Follow Up")
j = 7 ' Start copying to row 1 in target sheet
For Each c In Source.Range("J7:J120") ' Do 120 rows
If c = "Y" Then
Range("c").Select
Source.Range("C" & (ActiveCell.Row)).Copy Target.Range(j, 2)
j = j + 1
End If
Next c
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try changing

Code:
Source.Range("C" & (ActiveCell.Row)).Copy Target.[COLOR="#FF0000"]Range[/COLOR](j, 2)
to
Code:
Source.Range("C" & [COLOR="#FF0000"]c[/COLOR].Row).Copy Target.[COLOR="#FF0000"]Cells[/COLOR](j, 2)

and remove the line below

Code:
Range("c").Select
 
Last edited:
Upvote 0
Hi

Try this on a copy of your workbook.

Code:
Sub test()
    For i = 7 To 120
        If Range("'Screening Log'!J" & i) = "Y" Then _
            Range ("'OT and Follow Up'!A" & Range("'OT and Follow Up'!A" & Rows.Count).End(xlUp).Row) + 1 = Range("'Screening Log'!C" & i)
    Next
End Sub

Dave
 
Upvote 0
Thanks Mark858 and SQUIDD. I'll give both a try. I don't have access to the workbook until I'm back at work though. Who knew I'd be so keen to return to work on Monday? :D
 
Upvote 0
Hi again folks,

Your code worked Mark858 but now I have a new problem :( The macro is picking up the first entry in the source spreadsheet instead of picking up on those with Y in column J.

Code:
Sub UpdateEnrol()

Dim c As Range

Dim j As Integer

Dim Source As Worksheet

Dim Target As Worksheet


 ' Change worksheet designations as needed

Set Source = ActiveWorkbook.Worksheets("Screening Log")

Set Target = ActiveWorkbook.Worksheets("OT and Follow Up")

   

    j = 7 ' Start copying to row 1 in target sheet

    For Each c In Source.Range("J7:J120") ' Do 120 rows

        If c = "Y" Then

            Source.Range("C" & (ActiveCell.Row)).Copy Target.Cells(j, 2)

            j = j + 1

        End If

    Next c

   

End sub
[\code]
 
Upvote 0
I told you to make 2 adaptions to answer your specific query.

You were told to change
Code:
Source.Range("C" & (ActiveCell.Row)).Copy Target.Range(j, 2)

to
Code:
Source.Range("C" & [COLOR="#FF0000"]c.[/COLOR]Row).Copy Target.Cells(j, 2)

which you haven't done, see what you have in red below

Code:
Source.Range("C" & ([COLOR="#FF0000"]ActiveCell[/COLOR].Row)).Copy Target.Cells(j, 2)
 
Last edited:
Upvote 0
No problem, just a tip though copy and paste any code offered rather than adapt or re-type it :) and welcome to the forum.
 
Upvote 0

Forum statistics

Threads
1,215,085
Messages
6,123,030
Members
449,092
Latest member
ikke

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