hotkoreanchick
hotkoreanchick

Reputation: 49

Compliing error, Object Required in VBA

Sub MinSelected(R As Range)

Dim min As Double, tmp As String

min = Application.WorksheetFunction.min(R)
tmp = Application.WorksheetFunction.Text(min, "ddd/mm/dd/yyyy")
Range("F2").Select
ActiveCell = tmp
End Sub
Sub MaxSelectedd(S As Range)

Dim max As Double, tmp As String

max = Application.WorksheetFunction.min(S)
tmp = Application.WorksheetFunction.Text(max, "ddd/mm/dd/yyyy")
Range("G2").Select
ActiveCell = tmp

End Sub

Sub Main()
Dim myRange As Range
Set myRange = Selection

Module5.MinSelected (myRange)
MaxSelectedd (myRange)
End Sub

I'm fairly new to VBA and having some trouble with using Subs.

I'm trying to output min and max of the user selected range.

MinSelected method is in Module 5, and Main and MaxSelectedd are in Module 6.

Object required error occurs when I call Module5.Minselected(myRange).

Please help me figure out why.

Upvotes: 0

Views: 508

Answers (2)

Philippe.H
Philippe.H

Reputation: 302

The correct syntax is either:

Call MinSelected(myRange)
Call MaxSelectedd(myRange)

or you can use :

MinSelected myRange
MaxSelectedd myRange

Upvotes: 1

Marek Stejskal
Marek Stejskal

Reputation: 2708

You do not need to put Module5 before the sub, your sub/functions are public by default, meaning they can be called from all modules.

Also, you have a typo in you Max function, you are using a Worksheet min function again.

Upvotes: 0

Related Questions