queries in excel

  • Thread starter Thread starter gaby elia
  • Start date Start date
G

gaby elia

if we have a file in excel and there is a cell starting in number 1 and when
i want to close this sheet and reopen it again i wanna be 2 by auto ,so each
time i open this file i wanna this number to be increased automatically
 
Press Alt + F11 to open the VBE and then double click the ThisWorkbook object
in the project window.

In the Code pane change the value in the combo box on the left to Workbook
and the value in the combobox on the right to Open.

Enter the following line of code in the Workbook_Open() event


Sheets(1).Range("A1").Value = Sheets(1).Range("A1").Value + 1

Change the worksheet's index number to the reference the sheet you're
wanting to track the number of times the workbook is opened and the cell
address you want the total in. Sheets can also be referenced by their tab
name as follows.

Sheets("Sheet1").Range("A1").Value = Sheets("Sheet1").Range("A1").Value
+ 1
 
This will increment cell A1 in worksheet Sheet1:

Private Sub Workbook_Open()
With Sheets("Sheet1").Range("A1")
.Value = .Value + 1
End With
End Sub

This event macro goes in the workbook code area.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top