PLEASE TAKE A LOOK AT THIS CODE- MY BOSS IS AFTER MY HEAD FOR THIS FORM
Posted by Faye on November 14, 2001 5:28 AM
Hi,
I hope this is not too much to look at!!!!
I posted this earlier and no one has responded, I am going on Holdiday on Friday and this has to be handed over to my Boss before I go. I just can't seem to get this done and I am running out of time.
What I want to achieve here is that; when the message box asks if I want to continue and I say no,I want the worksheet to be saved and quit Excel. I have gotten it to work for my other workbooks but I don't know what is happening with this one.
If response = vbyes then
Textbox1.text=""
Textbox2.Text=""
Textbox1.Setfocus
Else
Unload Me.
Dim SelText As String
Dim i As Integer
Const PerilsCol = 19 'Perils in colum S
SelText = " ' "
With PerilsLbx
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
SelText = Right(SelText & ListBox1.List(i) & " ", Len(SelText & ListBox1.List(i) & " ") - 1)
End If
Next i
End With
'put value in next available cell in perils column
Cells(65536, PerilsCol).End(xlUp).Offset(1).Value = SelText
End If
End Sub
I substituted the "unload me" bit with code to save the workbook and exit excel and I get the error message (Runtime error 13 type mismatch) and it also shows the screen asking if I want to save the document, which I don't get with the other workbooks, but when I save the workbook and reopen it, the column for the listbox is empty. I even went as far as putting - If vbno then (execute code) and it still does not work. Could someone take a look at the above code and see if they could tell me what is wrong.
I find that when I get the error message it displays the code I have in Sheet1, but it does not highlight anything so that I can figure out what is wrong. Code for sheet1 is below.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rCells As Range
Application.EnableEvents = False
If Not Intersect(Target, Columns("A:Z")) Is Nothing Then
For Each rCells In Intersect(Target, Columns("A:Z"))
rCells = UCase(rCells.Text)
Next
End If
Application.EnableEvents = True
End Sub
Thanks,
Faye