Hello Everyone,
This is my first post hope it will fit in with the guidelines... I am getting this "Sub or Function not Defined" Compile time error. I don't understand, I give up. What realy bothers me here is that the below macro seems to work fine on my home computer with Excel 2013 but at work I get the Compile time error message.
Anyone have an idea what could be wrong? This macro simply goes through a list on Sheet4 looking up the data on Sheet2.
This is my first post hope it will fit in with the guidelines... I am getting this "Sub or Function not Defined" Compile time error. I don't understand, I give up. What realy bothers me here is that the below macro seems to work fine on my home computer with Excel 2013 but at work I get the Compile time error message.
Code:
Sub runMacro()
Dim first As Integer, last As Integer, counter As Integer, firstcol As Integer, lastcol As Integer
Dim user As String
Dim i As Integer
For i = 2 To Cells(Rows.counter, "A").End(xlUp).Row
user = ThisWorkbook.Sheets("Sheet4").Range("A" & i).Value
Call searching(user, first, last, counter, firstcol, lastcol)
ThisWorkbook.Sheets("Sheet4").Range("B" & i).Value = ThisWorkbook.Sheets("Sheet2").Range("D" & first).Value
ThisWorkbook.Sheets("Sheet4").Range("C" & i).Value = ThisWorkbook.Sheets("Sheet2").Range("A" & first).Value
If firstcol = 2 Then
ThisWorkbook.Sheets("Sheet4").Range("D" & i).Value = "SentByUser"
End If
If firstcol = 4 Then
ThisWorkbook.Sheets("Sheet4").Range("D" & i).Value = "ReceivedFromUser"
End If
ThisWorkbook.Sheets("Sheet4").Range("E" & i).Value = ThisWorkbook.Sheets("Sheet2").Range("D" & last).Value
ThisWorkbook.Sheets("Sheet4").Range("F" & i).Value = ThisWorkbook.Sheets("Sheet2").Range("A" & last).Value
If lastcol = 3 Then
ThisWorkbook.Sheets("Sheet4").Range("G" & i).Value = "SentByUser"
End If
If lastcol = 5 Then
ThisWorkbook.Sheets("Sheet4").Range("G" & i).Value = "ReceivedFromUser"
End If
ThisWorkbook.Sheets("Sheet4").Range("H" & i).Value = counter
Next
End Sub
Private Sub searching(user As String, first As Integer, last As Integer, counter As Integer, firstcol As Integer, lastcol As Integer)
counter = 1
searching = True
Dim notfound As Boolean
notfound = False
ThisWorkbook.Sheets("Sheet2").Activate
On Error GoTo errhandler
Cells.Find(What:=user, After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
first = ActiveCell.Row
firstcol = ActiveCell.Column
Cells.FindPrevious(After:=ActiveCell).Activate
last = ActiveCell.Row
lastcol = ActiveCell.Column
Cells.Find(What:=user, After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
first = ActiveCell.Row
Do Until ActiveCell.Row = last
counter = counter + 1
Cells.FindNext(After:=ActiveCell).Activate
Loop
If notfound = True Then
first = 1
last = 1
counter = 0
firstcol = 1
lastcol = 1
End If
errhandler:
notfound = True
Resume Next
End Sub
Anyone have an idea what could be wrong? This macro simply goes through a list on Sheet4 looking up the data on Sheet2.