VBA formula

Breezy21

New Member
Joined
Jun 7, 2021
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. MacOS
I am working with a database and right now I am manually inputting the name along with a specific number value. However some names have multiple number values that are different, right now I am having it where if the person has multiple number values I am placing them in a different row. This is becoming extremely redundant and so if someone knows how I can use vba code to make it a quicker process that'd be great.


For more detail:
I have two columns with names (column A and column B), as of right now all the number codes match with the names of column B, however for my main DB I only care about the names of column A.
And so I first run a lookup to check if the name from column A is in column B if it is print the key code, only issue is that It only prints the first value). Ideally it would print all the codes associated with that specific name separated by a comma and repeat all the way through column A.

If anyone can help ASAP that'd be great!! (Let me know if more info is needed)
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi Breezy21,

Not 100% certain of your requirement, if you could add a mock-up list of some data and what your desired outcome would be it would be helpful.

In the meantime, I have the small snippet of code below that will loop through names in column a concatenate a list of all matched codes separated with a ", " between them. It will need the list to be sorted alphabetically first to work as in my example data.

VBA Code:
Sub ListCodes()

Dim CodeList As String
Dim MessageString As String


For Each i In Range(Range("A2"), Range("A2").End(xlDown))

    If i.Value = i.Offset(-1, 0).Value Then
    
        CodeList = CodeList & ", " & i.Offset(0, 1).Value
    
    Else
    
        CodeList = i.Offset(0, 1).Value

    End If

    If i.Value <> i.Offset(1, 0).Value Then

    MessageString = "Name: " & i.Value & " - " & CodeList
    MsgBox MessageString
    
    Else
    
    End If

Next i

End Sub

My example with the message box showing the three matches for Amelia-Mae. You would use 'CodeList' to send to the printer instead of it being used in my 'MessageString' in this example.

1623109017302.png


Post some more details if you require more assistance.

Steven
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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