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

  • SEARCH
  • Home
  • 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 8546979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:09:38+00:00 2026-06-11T13:09:38+00:00

I have a reference set of data in a column of cells (it could

  • 0

I have a reference set of data in a column of cells (it could have been a row, but whatever).

I want to go through several worksheets, checking a selected range of values and if the current cell value is in the reference data, use it as the value to paste into an Offset of the next series of cells until the current cell has changed to some new value in the reference data, at which time the paste process should repeat for the new value and next series of cells.
e.g.

Sub doStuff()
Dim RefRange As Range, queryRange As Range, checkCell As Rnage
String pasteDate As String

Set RefRange = Range("A1:A50")
Set queryRange = .Selected

For Each checkCell In queryRange
  If checkCell.Value IN RefRange <***here's where I don't know what to use ***>
     pasteData = checkCell.Value
     ' Advance to next item
     Next
  ElseIf checkCell.Value Not In queryRange <***here's where I don't know what to use ***>
     ActiveCell.Offset(0,+1).Value = pasteData
  End If
Next
End Sub

I know how to do this in SQL, is there some similar method in VBA?

In SQL:

Select a, b from table where c in ('foo', 'bar', 'baz') OR

Select a, b from table where c in (select e from some_other_table)

TIA

  • 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-11T13:09:40+00:00Added an answer on June 11, 2026 at 1:09 pm

    I doubt there will be a need to loop through all the data simply use a formula in the entire column and replace with the resulting value. Like this:

    Sub Test()
    
        With ActiveSheet.UsedRange.Columns(3).Offset(1)
            .Formula = "=IF(ISERROR(MATCH(B2,A:A,0)),"""",B2)"
            .Value = .Value
        End With
    
    End Sub
    

    The code above looks at all values in the B column to test for a match in the A column. If match is found then the B column value is displayed in the c column. If no match is found it displays a blank cell but you can change that to whatever you want.

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a reference data member in a class, but I do
My project is ARC enabled (the build settings have Objective-C Reference Counting set to
I have parent/child relationship set up via Node Reference. A Child record can have
I have set the two buttons in preference.xml file. I want to go to
I have a reference application that I use to work through DDD issues, and
I have a repeater which binds a set of data. Within this repeater is
I have a row of data as follows: header1 header2 header3 header4 header5 row
I have been following the MSDN tutorial as a reference while making an MVC
I have an OHLC price data set, that I have parsed from CSV into
We have a sql script to update a set of sequences after seed data

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.