+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: Self deleting cell formulas

  1. #16
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Self deleting cell formulas

    To utilize the code, right click the name tab on the Master_Database worksheet. Select View Code. Paste the code into the window that opens. Every time something on the worksheet changes, such as adding a line of data, the code will execute.

  2. #17
    Registered User
    Join Date
    01-15-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Self deleting cell formulas

    Quote Originally Posted by dangelor View Post
    To utilize the code, right click the name tab on the Master_Database worksheet. Select View Code. Paste the code into the window that opens. Every time something on the worksheet changes, such as adding a line of data, the code will execute.
    I've sort of got it to work now (it's filling in the right column but doesn't recognize that the database headings are on row 50 and the data fills in from row 51, then 52, 53 etc.) but I'll explain why I won't be able to use it:

    The background to the issue I had using the spreadsheet formula as shown in my first post was that if an entry in the database was deleted, all the Number IDs would reassign themselves. So where you had 001, 002, 003, 004, 005 for example, if you deleted database row 004, the numbers would change to 001, 002, 003, 004 instead of: 001, 002, 003, 005. This issue could be solved by getting VBA code to assign the number but that's where I got stuck. See my post before last for the full layout of the spreadsheet / database I have.

    Thanks for the suggestion though, I feel I'm getting closer to the solution!

  3. #18
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Self deleting cell formulas

    Can you post a dummy file?

  4. #19
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Self deleting cell formulas

    If your form is writing to the database file, why not have it simply overwrite the formula with its value after entering the new data?
    Good luck.

  5. #20
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Self deleting cell formulas

    I suggested how to do this, gave you some leads not completed code as you asked. You haven't even used the suggestions.

    You have a userform that adds data to the sheet so you don't need sheet formulas for this.

    If the unique number is in Column A then

    Option Explicit
    
    Private Sub CommandButton1_Click()
        Dim NextRw As Long
        With Sheet1    '< sheet that has database
            NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            .Cells(NextRw, 1).Value = Format(Application.WorksheetFunction.Max(.Columns(1)) + 1, "000")
            'add rest of data
        End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  6. #21
    Registered User
    Join Date
    01-15-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Self deleting cell formulas

    Quote Originally Posted by royUK View Post
    I suggested how to do this, gave you some leads not completed code as you asked. You haven't even used the suggestions.

    You have a userform that adds data to the sheet so you don't need sheet formulas for this.

    If the unique number is in Column A then

    Option Explicit
    
    Private Sub CommandButton1_Click()
        Dim NextRw As Long
        With Sheet1    '< sheet that has database
            NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            .Cells(NextRw, 1).Value = Format(Application.WorksheetFunction.Max(.Columns(1)) + 1, "000")
            'add rest of data
        End With
    End Sub



    Thank you for your help. I did post an attempt with your initial suggestion (Post #12) but as I am still developing a basic understanding of VBA, I spend a lot of time not getting very far. I don't post all these attempts as I was didn't want to fill the board up with code that might divert from my original issue.

    I will have a go with the above.

  7. #22
    Registered User
    Join Date
    01-15-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    [Solved] Self deleting cell formulas

    Quote Originally Posted by royUK View Post
    I suggested how to do this, gave you some leads not completed code as you asked. You haven't even used the suggestions.

    You have a userform that adds data to the sheet so you don't need sheet formulas for this.

    If the unique number is in Column A then

    Option Explicit
    
    Private Sub CommandButton1_Click()
        Dim NextRw As Long
        With Sheet1    '< sheet that has database
            NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            .Cells(NextRw, 1).Value = Format(Application.WorksheetFunction.Max(.Columns(1)) + 1, "000")
            'add rest of data
        End With
    End Sub


    Brilliant! It works. I've incorperated this suggestion into what I had and ended up with the below:

     Private Sub Submit_Click()
    If MsgBox("Send to Database?", vbYesNo + vbQuestion) = vbNo Then
       Exit Sub
          
          Else
              
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Master_Database")
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
        SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
    ws.Cells(iRow, 2).Value = Application.WorksheetFunction.Max(Range("B50:B1050")) + 1  '< I set the first number of the range (cell B51, which is an "example" line in the database) as "000"
    
    'This transfers values from userform to database sheet.
    ws.Cells(iRow, 3).Value = Me.Answer1.Value
    ws.Cells(iRow, 4).Value = Me.Answer2.Value
    ws.Cells(iRow, 5).Value = Me.Answer3.Value
    
    'This clears the userform
    Me.Answer1.Value = ""
    Me.Answer2.Value = ""
    Me.Answer3.Value = ""
    Me.Answer1.SetFocus
    
    End If
    End Sub

    Sorry it took so long for all this to click in my head. I realise how simple the solution is now - particularly as I essentially had all the more complicated code I needed already. Thank you for your patience and for everybody's help. Much appreciated - I have learnt a lot in this short time!
    Last edited by SJJ; 02-13-2012 at 08:45 AM. Reason: Tidying up working solution so that it works for others.

  8. #23
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Self deleting cell formulas

    Glad we got there in the end.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0