excel macro

Brum, Mario 6 Reputation points
2022-03-24T02:05:29.347+00:00

Macro is not running - What am I doing wrong?

Public Static Sub Comments()
Dim DataRange As Range
Dim LastRow As Long
Dim Count As Integer
Dim Cnt2 As Integer
Dim PresalesDelivery As Integer
Dim col As Long
Dim row As Long
Dim answ As Integer
Dim cmt As Comment
Dim phrase, Name, chkphrase, word, temp 'As String
LastRow = 765 'May change if Rows are added [was:294]
Count = 99
phrase = ""
chkphrase = "Master Presales Delivery Blank"
word = ""
temp = ""
PresalesDelivery = 1

Set DataRange = Range("A4:N" & LastRow)
Worksheets("Presales").Range("D4:N765").ClearComments  'Clear old Comments
Worksheets("Delivery").Range("D4:N765").ClearComments  'Clear old Comments
Application.ScreenUpdating = False

For Each ws In Worksheets
   phrase = ws.Name
   If Left(phrase, 5) = "Blank" Then
      phrase = "Blank"
   End If
   Count = InStr(1, chkphrase, phrase, 1)
   If Count = 0 Then  'Process
      col = 4   'D or 4
      row = 4
      answ = 0

      Sheets(PresalesDelivery).Activate
      For row = 4 To LastRow     'Read row (4-30) Test:10-16
         If Len((Cells(row, 3).Value)) > 1 Then   'If Col 3 header Blank, skip
            For col = 4 To 14
               answ = Cells(row, col).Value
               If answ = 1 Then
                  'Sheets(2).Activate
                  If PresalesDelivery = 1 Then
                     Sheets("Presales").Activate
                  Else
                     Sheets("Delivery").Activate
                  End If
                  ActiveSheet.Cells(row, col).Select
                  If ActiveCell.Comment Is Nothing Then
                     ActiveCell.AddComment Text:="1-" & Name & Chr(10)
                  Else
                     phrase = ActiveCell.Comment.Text
                     Cnt2 = ((UBound(Split(phrase, Chr(10)))) + 1)
                     phrase = (phrase & Cnt2 & "-" & Name & Chr(10))
                     ActiveCell.Comment.Text Text:=phrase
                  End If
                  ActiveCell.Comment.Shape.TextFrame.AutoSize = True

                  Sheets(Name).Activate
                  ActiveSheet.Cells(row, col).Select
                  Exit For    'flag found, get out
               End If
            Next     'Col
         End If
      Next      'Row
   End If

Next ws
Application.ScreenUpdating = True
If PresalesDelivery = 1 Then
Sheets("Presales").Activate
Else
Sheets("Delivery").Activate
End If
ActiveSheet.Cells(1, 2).Select
Worksheets("Presales").Range("A2").Value = "(c) 7'19"
Worksheets("Delivery").Range("A2").Value = "(c) 7'19"
MsgBox "Done..."
End Sub

Developer technologies Visual Basic for Applications
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. CK 106 Reputation points
    2022-03-24T05:43:34.257+00:00

    Any error message?

    You might get more interest if you include more details in the title of your question too!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.