Excel VBA - Match all instances of a value in range and return adjacent values The Next CEO of Stack OverflowIs there a way to crack the password on an Excel VBA Project?How to avoid using Select in Excel VBAReferring to Dynamic Named Ranges in VBAExcel VBA - read cell value from codeVBA to split multi-line text in a excel cell into separate rows and keeping adjacent cell valuesAutomation with excel vbaVBA Excel - Range in Variant split by content criteriaExcel VBA: Loop through range and delete columns with all 0 valuesExcel VBA macro to send emails to unique users in range

In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact

What is the process for cleansing a very negative action

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Is it okay to majorly distort historical facts while writing a fiction story?

Airplane gently rocking its wings during whole flight

Why did early computer designers eschew integers?

Is it OK to decorate a log book cover?

Yu-Gi-Oh cards in Python 3

Spaces in which all closed sets are regular closed

free fall ellipse or parabola?

Is there such a thing as a proper verb, like a proper noun?

Reshaping json / reparing json inside shell script (remove trailing comma)

(How) Could a medieval fantasy world survive a magic-induced "nuclear winter"?

Film where the government was corrupt with aliens, people sent to kill aliens are given rigged visors not showing the right aliens

Is there a difference between "Fahrstuhl" and "Aufzug"?

Which one is the true statement?

How did Beeri the Hittite come up with naming his daughter Yehudit?

Redefining symbol midway through a document

What would be the main consequences for a country leaving the WTO?

Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

How do I fit a non linear curve?

Strange use of "whether ... than ..." in official text



Excel VBA - Match all instances of a value in range and return adjacent values



The Next CEO of Stack OverflowIs there a way to crack the password on an Excel VBA Project?How to avoid using Select in Excel VBAReferring to Dynamic Named Ranges in VBAExcel VBA - read cell value from codeVBA to split multi-line text in a excel cell into separate rows and keeping adjacent cell valuesAutomation with excel vbaVBA Excel - Range in Variant split by content criteriaExcel VBA: Loop through range and delete columns with all 0 valuesExcel VBA macro to send emails to unique users in range










0















I have a list of people, each belonging to one or multiple groups. I need to find out all the groups that each individual belongs to.



In one column, I have the list of names. In another column, I have the combined list of names belonging to each group, with no spaces or separators between names. I want the result to show each name next to a cell containing all groups the person belongs to. See the example below, where the yellow columns are the desired result:



enter image description here



I thought about creating an array for each name, but I haven't had any success. Here is the vba I have so far, not sure if I'm headed in the right direction.



 Sub Test()
Dim range_1 As Range
Dim range_2 As Range

Set range_1 = Range("Names")
Set range_2 = Range("Combined_Names")

Dim v As Variant

Dim myArray() As Double, X As Long
X = 0
ReDim Preserve myArray(X)
For Each cell In range_1
v = range_1.Value
If v <> "" Then
For Each cell In range_2
w = range_2.Value
If InStr(1, w, v, 1) Then
ReDim Preserve myArray(0 To X)
myArray(X) = cell.Offset(0, 1).Value
X = X + 1
End If
End If
Next
End Sub


Any advice or help would be greatly appreciated!










share|improve this question
























  • So the only way to distinguish your names is the capital letter? That is a really bad way to store data.

    – SJR
    Mar 7 at 19:14











  • This is just a way to put it for simplicity, the real data has larger values.

    – user3047983
    Mar 7 at 19:40











  • I don't understand your reply. You should post your data as is.

    – SJR
    Mar 8 at 8:32















0















I have a list of people, each belonging to one or multiple groups. I need to find out all the groups that each individual belongs to.



In one column, I have the list of names. In another column, I have the combined list of names belonging to each group, with no spaces or separators between names. I want the result to show each name next to a cell containing all groups the person belongs to. See the example below, where the yellow columns are the desired result:



enter image description here



I thought about creating an array for each name, but I haven't had any success. Here is the vba I have so far, not sure if I'm headed in the right direction.



 Sub Test()
Dim range_1 As Range
Dim range_2 As Range

Set range_1 = Range("Names")
Set range_2 = Range("Combined_Names")

Dim v As Variant

Dim myArray() As Double, X As Long
X = 0
ReDim Preserve myArray(X)
For Each cell In range_1
v = range_1.Value
If v <> "" Then
For Each cell In range_2
w = range_2.Value
If InStr(1, w, v, 1) Then
ReDim Preserve myArray(0 To X)
myArray(X) = cell.Offset(0, 1).Value
X = X + 1
End If
End If
Next
End Sub


Any advice or help would be greatly appreciated!










share|improve this question
























  • So the only way to distinguish your names is the capital letter? That is a really bad way to store data.

    – SJR
    Mar 7 at 19:14











  • This is just a way to put it for simplicity, the real data has larger values.

    – user3047983
    Mar 7 at 19:40











  • I don't understand your reply. You should post your data as is.

    – SJR
    Mar 8 at 8:32













0












0








0








I have a list of people, each belonging to one or multiple groups. I need to find out all the groups that each individual belongs to.



In one column, I have the list of names. In another column, I have the combined list of names belonging to each group, with no spaces or separators between names. I want the result to show each name next to a cell containing all groups the person belongs to. See the example below, where the yellow columns are the desired result:



enter image description here



I thought about creating an array for each name, but I haven't had any success. Here is the vba I have so far, not sure if I'm headed in the right direction.



 Sub Test()
Dim range_1 As Range
Dim range_2 As Range

Set range_1 = Range("Names")
Set range_2 = Range("Combined_Names")

Dim v As Variant

Dim myArray() As Double, X As Long
X = 0
ReDim Preserve myArray(X)
For Each cell In range_1
v = range_1.Value
If v <> "" Then
For Each cell In range_2
w = range_2.Value
If InStr(1, w, v, 1) Then
ReDim Preserve myArray(0 To X)
myArray(X) = cell.Offset(0, 1).Value
X = X + 1
End If
End If
Next
End Sub


Any advice or help would be greatly appreciated!










share|improve this question
















I have a list of people, each belonging to one or multiple groups. I need to find out all the groups that each individual belongs to.



In one column, I have the list of names. In another column, I have the combined list of names belonging to each group, with no spaces or separators between names. I want the result to show each name next to a cell containing all groups the person belongs to. See the example below, where the yellow columns are the desired result:



enter image description here



I thought about creating an array for each name, but I haven't had any success. Here is the vba I have so far, not sure if I'm headed in the right direction.



 Sub Test()
Dim range_1 As Range
Dim range_2 As Range

Set range_1 = Range("Names")
Set range_2 = Range("Combined_Names")

Dim v As Variant

Dim myArray() As Double, X As Long
X = 0
ReDim Preserve myArray(X)
For Each cell In range_1
v = range_1.Value
If v <> "" Then
For Each cell In range_2
w = range_2.Value
If InStr(1, w, v, 1) Then
ReDim Preserve myArray(0 To X)
myArray(X) = cell.Offset(0, 1).Value
X = X + 1
End If
End If
Next
End Sub


Any advice or help would be greatly appreciated!







excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 7:35









Pᴇʜ

24.9k63052




24.9k63052










asked Mar 7 at 18:13









user3047983user3047983

246




246












  • So the only way to distinguish your names is the capital letter? That is a really bad way to store data.

    – SJR
    Mar 7 at 19:14











  • This is just a way to put it for simplicity, the real data has larger values.

    – user3047983
    Mar 7 at 19:40











  • I don't understand your reply. You should post your data as is.

    – SJR
    Mar 8 at 8:32

















  • So the only way to distinguish your names is the capital letter? That is a really bad way to store data.

    – SJR
    Mar 7 at 19:14











  • This is just a way to put it for simplicity, the real data has larger values.

    – user3047983
    Mar 7 at 19:40











  • I don't understand your reply. You should post your data as is.

    – SJR
    Mar 8 at 8:32
















So the only way to distinguish your names is the capital letter? That is a really bad way to store data.

– SJR
Mar 7 at 19:14





So the only way to distinguish your names is the capital letter? That is a really bad way to store data.

– SJR
Mar 7 at 19:14













This is just a way to put it for simplicity, the real data has larger values.

– user3047983
Mar 7 at 19:40





This is just a way to put it for simplicity, the real data has larger values.

– user3047983
Mar 7 at 19:40













I don't understand your reply. You should post your data as is.

– SJR
Mar 8 at 8:32





I don't understand your reply. You should post your data as is.

– SJR
Mar 8 at 8:32












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050334%2fexcel-vba-match-all-instances-of-a-value-in-range-and-return-adjacent-values%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050334%2fexcel-vba-match-all-instances-of-a-value-in-range-and-return-adjacent-values%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved