tortillachips
New Member
- Joined
- Aug 9, 2011
- Messages
- 5
I want vba to search a sheet for a value. If the value exists, ask the user if they want to overwrite the values below it. If it does not exist, start a new set of values. The problem lies in my if statements.. If the user selects to overwrite the file. nothing happens. can anyone help?
Private Sub ButtonSaveValues_Click()
Dim irow As Long
Dim SaveFile As String
Dim x As Integer
Dim overwrite As Variant
Dim FoundValue As Range
Start:
SaveFile = InputBox("Enter the name you would like this to be saved under:", "Save File")
Sheets("Save").Activate
Range("A1").Activate
Set FoundValue = Cells.Find(what:=SaveFile, after:=ActiveCell, LookIn:=xlValues, lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, _
searchformat:=False)
If Not FoundValue Is Nothing Then
overwrite = MsgBox("There is already a file under this name, would you like to overwrite it?", vbYesNo)
If overwrite = vbNo Then Call ButtonSaveValues_Click
ElseIf overwrite = vbYes Then
irow = ActiveCell.Row
Call Saver
End If
Else
irow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Call Saver
End If
Private Sub ButtonSaveValues_Click()
Dim irow As Long
Dim SaveFile As String
Dim x As Integer
Dim overwrite As Variant
Dim FoundValue As Range
Start:
SaveFile = InputBox("Enter the name you would like this to be saved under:", "Save File")
Sheets("Save").Activate
Range("A1").Activate
Set FoundValue = Cells.Find(what:=SaveFile, after:=ActiveCell, LookIn:=xlValues, lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, _
searchformat:=False)
If Not FoundValue Is Nothing Then
overwrite = MsgBox("There is already a file under this name, would you like to overwrite it?", vbYesNo)
If overwrite = vbNo Then Call ButtonSaveValues_Click
ElseIf overwrite = vbYes Then
irow = ActiveCell.Row
Call Saver
End If
Else
irow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Call Saver
End If