Simple VBA Macro

aeddipa

Active Member
Joined
Jun 1, 2009
Messages
337
Hey guys,

I don't know if its the lack of sleep or lack of coffee in my system, but I can't figure out this relatively easy macro. Any help would be greatly appreciated.

I have two sheets of data on stocks. The second sheet contains some of the same stocks as on the first sheet. I have to bring the market value from the second sheet over to the first and add it with the market value on the 1st sheet. This will get me the sum of market values.

I have done this successfully, however, after doing this, I want to copy paste special the formulas to values and then delete the rows in the 2nd sheet that were used in sheet 1.

This will leave me with any data that is sepearate from sheet 1. I then want to sort the remaining stocks so that they are in order, copy and paste them into the bottom of sheet 1 in the format of sheet 1.

Here are some pictures to help.

Sheet 1:


Excel Workbook
ABCDE
1Underlying Stocks / Account HoldingsTickerMorningstar Mkt Value ($)Advent Mkt ValueSum of Mkt Value
2Microsoft CorporationMSFT560,543.60763,756.00$1,324,299.60
3J.P. Morgan Chase & Co.JPM500,892.08442,857.00$943,749.08
4ExxonMobil CorporationXOM857,048.800$857,048.80
5Wells Fargo CompanyWFC419,440.05322,617.00$742,057.05
morningstar

Sheet 2:

advent

<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 299px"><COL style="WIDTH: 95px"><COL style="WIDTH: 64px"></COLGROUP><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD></TD><TD>A</TD><TD>B</TD><TD>C</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD></TD><TD>Security</TD><TD>Market</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD>Security</TD><TD>Symbol</TD><TD>Value</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">8</TD><TD>--------------------</TD><TD>------------</TD><TD>----------------</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">9</TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">10</TD><TD>AGILENT TECHNOLOGIES INC COM</TD><TD>a</TD><TD style="TEXT-ALIGN: right">195733</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">11</TD><TD>APPLE INC COM</TD><TD>aapl</TD><TD style="TEXT-ALIGN: right">241718</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">12</TD><TD>ABBOTT LABS COM</TD><TD>abt</TD><TD style="TEXT-ALIGN: right">102039</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">13</TD><TD>BARRICK GOLD CORP COM</TD><TD>abx</TD><TD style="TEXT-ALIGN: right">518418</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">14</TD><TD>ADOBE SYS INC COM</TD><TD>adbe</TD><TD style="TEXT-ALIGN: right">124172</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">15</TD><TD>ANALOG DEVICES INC COM</TD><TD>adi</TD><TD style="TEXT-ALIGN: right">61670</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">16</TD><TD>AGNICO EAGLE MINES LTD COM</TD><TD>aem</TD><TD style="TEXT-ALIGN: right">31857</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">17</TD><TD>AES CORP COM</TD><TD>aes</TD><TD style="TEXT-ALIGN: right">40600</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">18</TD><TD>AETNA INC NEW COM</TD><TD>aet</TD><TD style="TEXT-ALIGN: right">238488</TD></TR></TABLE>

Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4



If someone could help me out with this it would be greatly appreciated. I just can't figure out the link in VBA to delete the rows in sheet 2 once they have been used on sheet 1.

Thanks!



EDIT:

Obviously in this example no symbol matches, but in the real data there are matches.
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,215,684
Messages
6,126,199
Members
449,298
Latest member
Jest

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