Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Complie Error with xlValues


Hi Folks,

I am new to the Whole VBA Programming and I am trying to insert
autofilter condition in a row, when a particluar string in th
worksheet is identified.

All I am getting is an error in the Find method ,when I reac
LookIn:= xlvalues. It give me the following

compile error:
Variable not defined

I am not sure, how to fix this error. I tried various options, but I a
not able to fix this issue.

Here is the code i am working on:


PHP code
-------------------
Sub formatWorkbook(xlApp As Object, filename As String)
'format the workbook
Dim xlWkbk As Object
Dim sheet As Object
Dim i As Variant
Dim test As Variant
Dim TopLeftCell As String
Dim UsdRng As String
Dim BottomRightCell As String
Dim FilterRange As String
Dim Findfor As String

Findfor = "Cust Master ID"
Set xlWkbk = xlApp.Workbooks.Open(filename) 'open the workbook

For i = 1 To xlWkbk.worksheets.Count
Set sheet = xlWkbk.sheets(i)
TopLeftCell = sheet.Range("A:A").Find(what:=Findfor, Lookin:=xlvalues).Address
UsdRng = sheet.UsedRange.Address
BottomRightCell = Right(UsdRng, Len(UsdRng) - InStr(UsdRng, ":"))
FilterRange = TopLeftCell & ":" & BottomRightCell
sheet.Range(FilterRange).AutoFilter
sheet.Range("A1").Select
Next i

xlWkbk.Save 'save the workbook
xlWkbk.Close 'close the workbook

Set xlWkbk = Nothing

End Sub 'formatWorkboo
-------------------


Any helps or suggestions would be appreciated.

Thank You

--
vincent_veg
-----------------------------------------------------------------------
vincent_vega's Profile: http://www.excelforum.com/member.php...fo&userid=3639
View this thread: http://www.excelforum.com/showthread.php?threadid=56175

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Complie Error with xlValues

Hi Vincent,

As written, you will receive an error message if the search string is not
found on any worksheet or if the workbook contains sheets of non-worksheet
type, e.g. a chart sheet. Additional errors will be experienced because a
selection can not be made on a non-active sheet.

Addressing these issues, try:

'=============
Sub formatWorkbook(xlApp As Object, filename As String)
'format the workbook
Dim xlWkbk As Object
Dim sheet As Object
Dim i As Variant
Dim test As Variant
Dim TopLeftCell As String
Dim UsdRng As String
Dim BottomRightCell As String
Dim FilterRange As String
Dim Findfor As String
Dim rng As Range

Findfor = "Cust Master ID"
Set xlWkbk = xlApp.Workbooks.Open(filename) 'open the workbook

For i = 1 To xlWkbk.Worksheets.Count
Set sheet = xlWkbk.WorkSheets(i)
Set rng = sheet.Range("A:A").Find(what:=Findfor, _
LookIn:=xlValues)
If Not rng Is Nothing Then
TopLeftCell = rng.Address
UsdRng = sheet.UsedRange.Address
BottomRightCell = Right(UsdRng, _
Len(UsdRng) - InStr(UsdRng, ":"))
FilterRange = TopLeftCell & ":" & BottomRightCell
sheet.Range(FilterRange).AutoFilter
Application.Goto Reference:=sheet.Range("A1")
End If
Next i

xlWkbk.Save 'save the workbook
xlWkbk.Close 'close the workbook

Set xlWkbk = Nothing

End Sub 'formatWorkbook
'<<=============

FWIW, I would not use Sheet as a variable as I would find it very
confusing:: perhaps try a more conventional WS, wks or SH


---
Regards,
Norman



"vincent_vega"
wrote in message
news:vincent_vega.2azzxh_1152985808.3369@excelforu m-nospam.com...

Hi Folks,

I am new to the Whole VBA Programming and I am trying to insert a
autofilter condition in a row, when a particluar string in the
worksheet is identified.

All I am getting is an error in the Find method ,when I reach
LookIn:= xlvalues. It give me the following

compile error:
Variable not defined

I am not sure, how to fix this error. I tried various options, but I am
not able to fix this issue.

Here is the code i am working on:


Formula:
--------------------
Sub formatWorkbook(xlApp As Object, filename As String)
'format the workbook
Dim xlWkbk As Object
Dim sheet As Object
Dim i As Variant
Dim test As Variant
Dim TopLeftCell As String
Dim UsdRng As String
Dim BottomRightCell As String
Dim FilterRange As String
Dim Findfor As String

Findfor = "Cust Master ID"
Set xlWkbk = xlApp.Workbooks.Open(filename) 'open the workbook

For i = 1 To xlWkbk.worksheets.Count
Set sheet = xlWkbk.sheets(i)
TopLeftCell = sheet.Range("A:A").Find(what:=Findfor,
Lookin:=xlvalues).Address
UsdRng = sheet.UsedRange.Address
BottomRightCell = Right(UsdRng, Len(UsdRng) - InStr(UsdRng, ":"))
FilterRange = TopLeftCell & ":" & BottomRightCell
sheet.Range(FilterRange).AutoFilter
sheet.Range("A1").Select
Next i

xlWkbk.Save 'save the workbook
xlWkbk.Close 'close the workbook

Set xlWkbk = Nothing

End Sub 'formatWorkbook
--------------------


Any helps or suggestions would be appreciated.

Thank You.


--
vincent_vega
------------------------------------------------------------------------
vincent_vega's Profile:
http://www.excelforum.com/member.php...o&userid=36397
View this thread: http://www.excelforum.com/showthread...hreadid=561756



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Complie error - can You Help Anthony Excel Programming 2 October 9th 05 10:51 PM
Complie Error Help JMay Excel Programming 4 January 24th 05 04:33 AM
complie error brian Excel Programming 2 December 13th 04 06:51 PM
Complie Error chris huber Excel Programming 3 January 14th 04 09:57 AM
Variable produces a complie error Btinker Excel Programming 1 November 26th 03 07:53 PM


All times are GMT +1. The time now is 06:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"