poobs_away
New Member
- Joined
- Aug 1, 2011
- Messages
- 12
Not entirely sure how to title what I need doing, so I hope the one I chose is alright. I'm fairly new to VBA, so I don't know much, and this is my first post here.
OK, this is a bit complicated, so let me set up an example of what I'm dealing with before I go on to explain what I need in the macro. Say I have a list of names in column a, some of them being the same; in column B I have numbers corresponding to those names:
john 21
john 14
lee 57
gary 12
except think along the lines of 500 or so rows of this. What I need to do is have a macro that starts at cell A1 looks at the name inside, then searches the rest of the column for duplicates. Once it's done that, it needs to go over to the B column and enter in all the numbers from the duplicate names it found into an equation, which for now will be just adding them up. Next it needs to take that sum and store it as a variable somewhere for future use in another macro(as I'll need to eventually plug these numbers into a larger equation. Definitely unsure if this part is possible), something like a=35, b=57, c=12.Finally it needs to note which cells it used in A so that when it loops to the next name it doesn't go to, in this case, a2 and find john again, but a3 to find lee. It would loop like this, adding up all the duplicates and assigning everything variables until it reaches a blank cell which would stop it.
Note that I don't want these variables to replace the current table, just to store them in the background somewhere for future use so that I could do something like a^2, which was john's variable in this example, and get 35x35.
I hope I explained this well enough, I don't know how much of this is actually possible, but anything is better than what I have right now, which is absolutely nothing.
OK, this is a bit complicated, so let me set up an example of what I'm dealing with before I go on to explain what I need in the macro. Say I have a list of names in column a, some of them being the same; in column B I have numbers corresponding to those names:
john 21
john 14
lee 57
gary 12
except think along the lines of 500 or so rows of this. What I need to do is have a macro that starts at cell A1 looks at the name inside, then searches the rest of the column for duplicates. Once it's done that, it needs to go over to the B column and enter in all the numbers from the duplicate names it found into an equation, which for now will be just adding them up. Next it needs to take that sum and store it as a variable somewhere for future use in another macro(as I'll need to eventually plug these numbers into a larger equation. Definitely unsure if this part is possible), something like a=35, b=57, c=12.Finally it needs to note which cells it used in A so that when it loops to the next name it doesn't go to, in this case, a2 and find john again, but a3 to find lee. It would loop like this, adding up all the duplicates and assigning everything variables until it reaches a blank cell which would stop it.
Note that I don't want these variables to replace the current table, just to store them in the background somewhere for future use so that I could do something like a^2, which was john's variable in this example, and get 35x35.
I hope I explained this well enough, I don't know how much of this is actually possible, but anything is better than what I have right now, which is absolutely nothing.