If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Adding contents of two tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-24-11, 03:58
JLR JLR is offline
Registered User
 
Join Date: Sep 2003
Location: London, England
Posts: 46
Adding contents of two tables

I wish to use VBA to add the data from one table (C3:AK18 in Sheet1) to the data of another table (C3:AK18 in Sheet2). Both tables just contain numbers and the tables are obviously the same size. How do you create a button so that when it is clicked the data from the first table is automatically added to the data in the second table? I am a beginner when it comes to VBA.
Reply With Quote
  #2 (permalink)  
Old 05-24-11, 11:03
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Hi,

Just to be clear, which of these results do you want?
Table 1 (example)
Code:
1    1
2    3
Table 2 (example)
Code:
0    1
2    3
Result (A) - Table 2
Code:
1    2
4    6
Result (B) - Table 2
Code:
0    1
2    3
1    1
2    3
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #3 (permalink)  
Old 05-24-11, 11:09
JLR JLR is offline
Registered User
 
Join Date: Sep 2003
Location: London, England
Posts: 46
Adding contents of two tables

I am hoping for the result you have called (A), thank you.
Reply With Quote
  #4 (permalink)  
Old 05-24-11, 14:35
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Here's one way of many:
Code:
Sub Button1_Click()
 
    Sheet2.Range("TableB").Value = [Sheet1!TableA + Sheet2!TableB]
 
End Sub
Attached Files
File Type: zip Book1.zip (13.0 KB, 5 views)
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #5 (permalink)  
Old 05-24-11, 14:45
JLR JLR is offline
Registered User
 
Join Date: Sep 2003
Location: London, England
Posts: 46
Adding contents of two tables

Thank you, Colin.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On