I'm looking for a vba solution for this search and add a formula task

zigen9

New Member
Joined
Dec 13, 2022
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
Hello all,

I have been always thinking for a solution for this task, I have spreadsheet A with a "column A" with a bunch model names(model name repeats in different rows) and "column B" with their prices.
I have another spreadsheet with a summary of these model names on "Column C" and addition to price on "Column D"

I would like to search C1 cell to "column A" and add D2 cell to "column B", problem is C1 repeats and do the same process until no more duplicates and search C2.
Really trying my best to explain this. Please shed me some light about this solution. Thank you.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Welcome to the Board!

I think the best thing to do would be to show us a small sample of your data, and then show us what your expected results of that example should looke like.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Thank you very much. I'm sorry i'm new to this forum and would like to learn more from experts like you. I will prepare my data and post again later. Thanks again.
 
Upvote 0
Thank you very much. I'm sorry i'm new to this forum and would like to learn more from experts like you. I will prepare my data and post again later. Thanks again.
You are welcome.
Just be sure to continue posting in this thread (don't start a new one for the same question).
 
Upvote 0
Hello Joe4,

Please see attached the example for the task I am facing.

Step1 is to search E2 model name to column A and add F2 to column B cells, there will be multiple E2 names in column A that needs to add F2 number to column B.

Step2 is to search E3 model name to column A and add F3 to colmn B cells...

Just need to keep going until the end of the list on column E.

Is there a vba example that I can follow? Please let me know. Any help would be great. Thank you so much.
 

Attachments

  • example.png
    example.png
    132.6 KB · Views: 7
Upvote 0
If your values in column B really are formulas like that, adding up multiple values, then this VBA code should do what you want:
VBA Code:
Sub AddValues()

    Dim lrA As Long, lrE As Long
    Dim rA As Long, rE As Long
    Dim m As String
    Dim v As Double
    
    Application.ScreenUpdating = False
    
'   Find last row in column A with data
    lrA = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Find last row in column E with data
    lrE = Cells(Rows.Count, "E").End(xlUp).Row
    
'   Loop through all values in column E
    For rE = 2 To lrE
'       Get value to look up and its corresponding value
        m = Cells(rE, "E")
        v = Cells(rE, "F").Value
'       Loop through values in column A
        For rA = 2 To lrA
'           Check to see if values match
            If Cells(rA, "A") = m Then
                Cells(rA, "B").Formula = Cells(rA, "B").Formula & "+" & v
            End If
        Next rA
    Next rE
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Hello Joe4,

This is absolutely incredible!!! Thank you for this vba code and as well as the lesson in this code. Can I make a donation to you for a beer at least? I really do appreciate you for this.

Thank you again Joe4.
 
Upvote 0
You are welcome.
Glad I was able to help!

We don't accept donations, but feel free to make a donation to your favorite charity on my behalf!
:)
 
Upvote 0
Thank you again Joe4. I will make this donation on your behalf.
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,709
Members
449,118
Latest member
MichealRed

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