Hey Guys, I am a newbie here (and to macs as well!) But I have developed an xla that seems to crash my excel (I am using excel 2004). However, if I compile first then run everything seems to be ok OR if I run the code directly from the VB editor it seems to run just fine. The SQL code is definitely right as I used it many times. I have much more complicated codes written that work well so I am sure there is an error in my code that I am overlooking and I am pulling my hair out trying to find it. Could you please take a look at the code and feel free to make any changes......

[VBA]Public Sub Convert()
Application.EnableEvents = False
Application.ScreenUpdating = False

Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight

Range("D1").Select
Range(Selection, Selection.End(xlDown)).Select
sql_filter = SQL_WHERE(Selection)
StopCounter = Selection.Rows.Count

If StopCounter = 65536 Then

SQL1 = "xxxxxxx"
connstring = "ODBC;DSN=xxxx;UID=xxxx;pwd=xxxx;"


With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=SQL1)
.Refresh
End With

Else

SQL1 = "xxxxxxx"
connstring = "ODBC;DSN=xxxx;UID=xxxx;pwd=xxxx;"

With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=SQL1)
.Refresh
End With

End If

Range("C1").Select
ActiveCell.Formula = "=VLOOKUP(D1,A:A:B:B,2,0)"

If StopCounter = 65536 Then
Else
Selection.AutoFill Destination:=Range("C1:C" & StopCounter)
Range("C1:C" & StopCounter).Select
End If

Columns("C:C").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Columns("A:B").Select
Range("B1").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("A1").Select

Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub[/VBA]
[uvba].[/uvba]
~Oorang