Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Compile error, variable not defined

The macro below cleans up spreadsheets created by SPSS. It changes some
cell formatting and replaces a bunch of "#NULLS!" with blanks. But it
hangs up with a "Compile error, variable not defined" error at the line
indicated below. Since Worksheet is an object, not a variable, I don't
understand the message. I even looked it up in the Object Browser. So
why doesn't VBA recognize it? It even capitalized it when I entered it,
which I thought, meant it recognized it. But now it doesn't!

Sub SPSSDownloadCleanup()


Dim FoundCell As Range
Dim CurCol As Range

Set FoundCell = ActiveSheet.Range("a1:z1").find(What:="clientid",
LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then
Set CurCol = Worksheet.Range.Column<----error here
CurCol.NumberFormat = "@"
CurCol.HorizontalAlignment = xlRight


Cells.Replace What:="#NULL!", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Else
End If

Set FoundCell = ActiveSheet.Range("a1:z1").find(What:="stateid",
LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then

Selection.HorizontalAlignment = xlCenter

Else
End If


End Sub

Does anyone see what I'm missing?
Thanks for the help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Compile error, variable not defined

You haven't specified which worksheet. You can use Activesheet,
Worksheets("sheet name"), or Worsksheets(n) where n is the index number.

--
HTH

Bob Phillips

"davegb" wrote in message
oups.com...
The macro below cleans up spreadsheets created by SPSS. It changes some
cell formatting and replaces a bunch of "#NULLS!" with blanks. But it
hangs up with a "Compile error, variable not defined" error at the line
indicated below. Since Worksheet is an object, not a variable, I don't
understand the message. I even looked it up in the Object Browser. So
why doesn't VBA recognize it? It even capitalized it when I entered it,
which I thought, meant it recognized it. But now it doesn't!

Sub SPSSDownloadCleanup()


Dim FoundCell As Range
Dim CurCol As Range

Set FoundCell = ActiveSheet.Range("a1:z1").find(What:="clientid",
LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then
Set CurCol = Worksheet.Range.Column<----error here
CurCol.NumberFormat = "@"
CurCol.HorizontalAlignment = xlRight


Cells.Replace What:="#NULL!", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Else
End If

Set FoundCell = ActiveSheet.Range("a1:z1").find(What:="stateid",
LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then

Selection.HorizontalAlignment = xlCenter

Else
End If


End Sub

Does anyone see what I'm missing?
Thanks for the help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Compile error, variable not defined

what about....

Set CurCol = ActiveSheet.Range.Column

:-D
does it work better ?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Compile error, variable not defined

ha, no it doesn't :-/
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Compile error, variable not defined

oh, you have the same problem with Range. If you want to refer to the find
results, just use

Set CurCol = cell.EntireColumn

--
HTH

Bob Phillips

"Bob Phillips" wrote in message
...
You haven't specified which worksheet. You can use Activesheet,
Worksheets("sheet name"), or Worsksheets(n) where n is the index number.

--
HTH

Bob Phillips

"davegb" wrote in message
oups.com...
The macro below cleans up spreadsheets created by SPSS. It changes some
cell formatting and replaces a bunch of "#NULLS!" with blanks. But it
hangs up with a "Compile error, variable not defined" error at the line
indicated below. Since Worksheet is an object, not a variable, I don't
understand the message. I even looked it up in the Object Browser. So
why doesn't VBA recognize it? It even capitalized it when I entered it,
which I thought, meant it recognized it. But now it doesn't!

Sub SPSSDownloadCleanup()


Dim FoundCell As Range
Dim CurCol As Range

Set FoundCell = ActiveSheet.Range("a1:z1").find(What:="clientid",
LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then
Set CurCol = Worksheet.Range.Column<----error here
CurCol.NumberFormat = "@"
CurCol.HorizontalAlignment = xlRight


Cells.Replace What:="#NULL!", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Else
End If

Set FoundCell = ActiveSheet.Range("a1:z1").find(What:="stateid",
LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then

Selection.HorizontalAlignment = xlCenter

Else
End If


End Sub

Does anyone see what I'm missing?
Thanks for the help!







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Compile error, variable not defined

If I understand your code right, you want the entire column formatted
correct? If so, change
Set CurCol = Worksheet.Range.Column, to
Set Curcol = ActiveCell.EntireColumn

Does that help?

*** Sent via Developersdex http://www.developersdex.com ***
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
Finding files in a folder. Variable not defined error. Ayo Excel Discussion (Misc queries) 1 March 14th 08 01:14 PM
Microsoft Visual Basic: Compile error: Sum or Function not defined Dmitry Excel Worksheet Functions 12 April 3rd 06 07:28 AM
"Compile error: sub or function not defined" Joe Excel Discussion (Misc queries) 4 January 30th 06 08:19 PM
compile error: expected variable or function MMM Excel Discussion (Misc queries) 3 December 24th 04 03:11 PM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Excel Programming 6 June 9th 04 03:40 PM


All times are GMT +1. The time now is 09:53 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"