referring to worksheets by name in a vba fourier transform

J

JacksonRJones

Hello. I was trying to call a fourier transform from vba and refer to the
worksheet the input data was on using a string variable. Here's the code:

Application.Run "ATPVBAEN.XLA!Fourier", sheetindex.Range("M15:M1038"),
sheetindex.Range("O15:O1037"), False, False

where sheetindex is a string type variable containing the name of the
worksheet. The following code works if the data is on sheet1:

Application.Run "ATPVBAEN.XLA!Fourier", sheet1.Range("M15:M1038"),
sheet1.Range("O15:O1037"), False, False

I get an error which says "invalid qualifier". I also tried setting the
active worksheet to the worksheet named by the string type variable and then
writing Activeworksheet.range to try and get the range right, but that didn't
work either. Any help would be greatly appreciated,

Jackson
 
V

Vasant Nanavati

Your confusion arises because Sheet1 is the worksheet name as well as the
object itself. To use the worksheet name, you need to use something like:

Worksheets("sheetindex").Range("M15:M1038")
 
N

Niek Otten

<Worksheets("sheetindex").Range("M15:M1038")>

Probably without the quotes around sheetindex
 
D

Dana DeLouis

Here's a general outline of something I use when working with Fourier
Analysis.
Note the use of " Worksheets(Sht)" where Sht is the name of the worksheet.

Sub Demo()
'// Dana DeLouis
Dim Sht As String
Dim DataIn, DataOut
Dim n, t

'// Functions Here:
Const FFT As String = "ATPVBAEN.XLA!Fourier"

'// Your string
Sht = "Sheet1"

Set DataIn = Worksheets(Sht).Range("M15:M1038")
Set DataOut = Worksheets(Sht).Range("O15")

'// Quick Check of input size...
n = DataIn.Cells.Count
t = Round(Log(n) / Log(2), 10)

If t - Int(t) <> 0 Then
MsgBox "Wrong size of input..." & n
Exit Sub
End If

'// FFT Bug...Clear Output first
DataOut.Resize(n, 1).ClearContents
Run FFT, DataIn, DataOut
End Sub
 
V

Vasant Nanavati

Thanks, Niek; my mistake.

Regards,

Vasant

Niek Otten said:
<Worksheets("sheetindex").Range("M15:M1038")>

Probably without the quotes around sheetindex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top