Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:15:28+00:00 2026-06-14T19:15:28+00:00

I have three columns, A, B and C: Column A contains names, NAME1, NAME2,

  • 0

I have three columns, A, B and C:
Column A contains names, NAME1, NAME2, etc.
Column B contains only the values “YES” or “NO”.
Column C is suppose to contain the names from column A that have value “YES” in column B.

I can say that as long as the value is “YES” in column B, copy the value from column A to column C. Very simple with:

C1=IF(B1="YES",A1,"")

But this will include blank cells, which I don’t want to. So I guess I am looking for a way to copy all the names from column A with value “YES” in column B and paste them into column C skipping the blanks.

I did find a VBA project that colors all the cells within a column with a certain value. I am not sure how to edit this into what I need. Here is the code I came up with so far.

ISSUES
1) Runtime Error ‘1004’ Application-defined or Object-defined error
2) Copying from Column A
3) Check and Remove Duplicates from NewRange

EDIT 1: Added comment rows into the code
EDIT 2: Change NewRange to be made from column A with Offset (untested due to runtime error)
EDIT 3: Code for copying form one sheet separated from code for pasting into another sheet
EDIT 4: Added correction from user @abahgat
EDIT 5: Remove duplicates

Sub RangeCopyPaste()
Dim cell As Range
Dim NewRange As Range
Dim MyCount As Long
MyCount = 1

'--> Loop through each cell in column B
'--> Add each cell in column A with value "YES" in column B to NewRange 
For Each cell In Worksheets("Sheet1").Range("B1:B30")
    If cell.Value = "YES" Then
        If MyCount = 1 Then Set NewRange = cell.Offset(0,-1)
        Set NewRange = Application.Union(NewRange, cell.Offset(0,-1))
        MyCount = MyCount + 1
    End If
Next cell

'--> Copy NewRange from inactive sheet into active sheet
NewRange.Copy Destination:=activesheet.Range("C1")

'--> Remove Duplicates
activesheet.Range("C1:C30").RemoveDuplicates

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:15:29+00:00Added an answer on June 14, 2026 at 7:15 pm

    This will do the trick:

    Sub RangeCopyPaste()
      Dim cell As Range
      Dim NewRange As Range
      Dim MyCount As Long
      MyCount = 1
    
      For Each cell In Worksheets("Sheet1").Range("B1:B30")
          If cell.Value = "YES" Then
              If MyCount = 1 Then Set NewRange = cell.Offset(0,-1)
              Set NewRange = Application.Union(NewRange, cell.Offset(0,-1))
              MyCount = MyCount + 1
          End If
      Next cell
    
      NewRange.Copy Destination:=activesheet.Range("D1")
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 columns, name1 and name2, that contain numerous rows of possible names.
I have a list containing three columns. The first column contains Names and the
I have a table with three columns, and two cells contain select boxes with
I have data stored in three columns of Excel Column A: Serial Number Column
I have a table that contains an Id column as a primary key. There
I have three columns in mysql table: tax_id, company_name, store_name. I need that tax_id
I have three column in my datagridview .One is text ,one is Combo and
I have three columns, y, m, and d (year, month, and day) and want
a have three column layout and i want to have three divs inside the
i have three columns for Date In, Date Out, Total Days. If in Date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.