简体   繁体   中英

Excel VBA Workbook_open event handler required

I have reference data in columns A and B on Sheet2 of my WorkBook . I have a blank sheet - Sheet1 - which i need to fill from my database.

I want to use Excel VBA to fill Sheet1 based on data in columns A and B in Sheet2 .

I use the reference data by.

  • I populate values in column A in Sheet1 from DB.
  • I check if the values stored in sheet 1, column A exist in Sheet2 column A,
  • If so, I populate into sheet 1 column B, the corresponding data i've found in Sheet2 column B.
  • Open , do alt + F11 that will open the IDE.
  • In the right hand window should see vba project and in brackets the name of the excel book you have open.
  • At the bottom of the list of sheets is an object called ThisWorkbook , right click it, and select View Code .
  • At top of should see two combo boxes, right hand one should say General click on it and select Workbook from the list.

This should give you the following

 Private Sub Workbook_Open()

 End Sub

This is the event that is fired each time the work book is opened. Now you will need to add code to reference the sheets in the workbook.

Here is some methods for how to reference sheets in vba Reference sheets . Next step will be to refer to the cells in the sheets see - > excel ranges as an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM