simi_av8r 0 Posted November 15, 2009 Report Share Posted November 15, 2009 Wanted: MS Excel VBA coder required Job Description: De-bugging partially inoperative VBA code written by (yours truly) Simi_av8r. Successful candidate will be highly proficient in VBA use within MS Excel. Can you help, then read on... Basically, the code relates to an order form within a spreadsheet that i'm working on for Mrs. Av8r... It all seems to work, except the part where, if you can understand the code, it is supposed to copy the old cell data from the cell into a new comment for the cell on entering the new data from the form...lost? Then this isn't for you...Still following me, good well, here's the code, can yo see where i've go wrong??: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target = "" Then prevalue = "a blank" Else: prevalue = Target.Value End If End Sub Public Sub Cancel_DMD() Dim datatoFind, sRemark As Variant Dim sheetCount As Integer Dim counter As Integer Dim currentSheet As Integer Dim searchRange As Variant Dim prevalue As String msgbox ("Please contact the Demands Clerk on Ext. xxxx to advise of this cancellation.") currentSheet = ActiveSheet.Index datatoFind = InputBox("Demand Number To Cancel:") If datatoFind = "" Then Exit Sub sheetCount = ActiveWorkbook.Sheets.Count If IsError(CDbl(datatoFind)) = False Then datatoFind = CDbl(datatoFind) For counter = 1 To sheetCount Sheets(counter).Activate 'defines the search to column A of the active sheet Set searchRange = ActiveSheet.Columns(1).Find(What:=datatoFind, LookIn:=xlValues, LookAt _ :=xlWhole, SearchOrder:=xlColumns, SearchDirection:=xlNext, MatchCase:=False) If Not searchRange Is Nothing Then 'test to see if the search is successful or not Worksheets("demands").Unprotect Password:="password" askRemark: sRemark = InputBox("Reason for cancellation") If sRemark = "" Then GoTo askRemark 'returns to ask reason for cancelling if left empty Range(searchRange.Address).EntireRow.Interior.ColorIndex = 3 Cells(searchRange.Row, "N").Value = sRemark Cells(searchRange.Row, "N").ClearComments Cells(searchRange.Row, "N").AddComment.Text Text:="Previous Value was " & prevalue & Chr(10) & "Canceled by " & Environ("UserName") & " on " & Chr(10) & Format(Date, "dd-mm-yyyy") Worksheets("demands").Protect Password:="password" Exit Sub 'quits when a match is found End If Next counter Sheets(currentSheet).Activate Worksheets("demands").Protect Password:="password" If searchRange Is Nothing Then msgbox ("Demand not found") 'searchRange is empty if Demand number was not found End Sub Link to post Share on other sites
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now