Cell value based on another cell if text in there's specific text in another cell

carlomscalisi

New Member
Joined
Jun 20, 2016
Messages
16
Hopefully the title wasn't too confusing.

I have a workbook with two sheets. On one sheet I have a column for comments and an adjacent column with a list value of "Y" or "N". Then I have another sheet and on that sheet I would like to have a column that contains the comments from the other sheet IF the adjacent column contains "Y". I hope that makes sense. Please help!


Thank you!
 
Try this macro. It will prompt you to enter the name of the reference sheet.
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet, response As String
    response = InputBox("Please enter the name of the reference sheet.")
    If response = "" Then Exit Sub
    Set srcWS = Sheets(response)
    Set desWS = Sheets("Follow-up")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With srcWS
        .Range("M1:M" & LastRow).AutoFilter Field:=1, Criteria1:="Y"
        .Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Copy desWS.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        .Range("L2:L" & LastRow).SpecialCells(xlCellTypeVisible).Copy desWS.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
        .Range("M1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub

Is there a way to only copy the values, and not the formatting of the other cells?
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try:
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet, response As String
    response = InputBox("Please enter the name of the reference sheet.")
    If response = "" Then Exit Sub
    Set srcWS = Sheets(response)
    Set desWS = Sheets("Follow-up")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With srcWS
        .Range("M1:M" & LastRow).AutoFilter Field:=1, Criteria1:="Y"
        .Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Copy
        desWS.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        .Range("L2:L" & LastRow).SpecialCells(xlCellTypeVisible).Copy
        desWS.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        .Range("M1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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