macro runs except from function

  • Thread starter Thread starter Brenda
  • Start date Start date
B

Brenda

I have a macro that copy pastes rows. This works fine if I
run it from the Run Macro inside excel.
I tried to make a function and call it from the function,
but it does nothing? It steps through but changes nothing
on the sheet. It is like it can't find the sheet

cell has formula
=check4diff(B6,B5)


Function check4diff(Old_Value, New_Value)

If Old_Value=New_Value Then
check4diff=1
Else
Application.Run("insertrowandcopy")
' I also tried the Call syntax and it was no different
check4diff=2
End If

End Function

Sub insertrowandcopy()

Worksheets("Sheet1").Activate
Worksheets("Sheet1").Rows(5).Copy
Worksheets("Sheet1").Rows(7).Select
Selection.Insert Shift:=xlDown

End Sub
 
Brenda said:
I have a macro that copy pastes rows. This works fine if I
run it from the Run Macro inside excel.
I tried to make a function and call it from the function,
but it does nothing? It steps through but changes nothing
on the sheet. It is like it can't find the sheet

cell has formula
=check4diff(B6,B5)


Function check4diff(Old_Value, New_Value)

If Old_Value=New_Value Then
check4diff=1
Else
Application.Run("insertrowandcopy")
' I also tried the Call syntax and it was no different
check4diff=2
End If

End Function

Sub insertrowandcopy()

Worksheets("Sheet1").Activate
Worksheets("Sheet1").Rows(5).Copy
Worksheets("Sheet1").Rows(7).Select
Selection.Insert Shift:=xlDown

End Sub

"It steps through but changes nothing on the sheet" because worksheet
functions are not allowed to change anything in any worksheet.
 
Back
Top