LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Selection Error

I am having a problem with my macros not wanting to run if I use
"selection" in the coding. I am using the exact same code that I had
been using in the past, i just placed it in a new add-in I am creating.
But now I keep getting errors. Is there such a thing as a macro that
will screw up "selection" in the whole workbook? Sometimes I can place
individual macros in workbooks and it will work.

here is an example of code that I use:

Sub MarkDupes()
Dim rConstRange As Range, rFormRange As Range
Dim rAllRange As Range, rCell As Range
Dim iCount As Long
Dim strAdd As String

Application.ScreenUpdating = False
On Error Resume Next
Set rAllRange = Selection
If WorksheetFunction.CountA(rAllRange) < 2 Then
MsgBox "You selection is not valid", vbInformation
On Error GoTo 0
Exit Sub
End If

Selection.EntireColumn.Insert

Set rConstRange = rAllRange.SpecialCells(xlCellTypeConstants)
Set rFormRange = rAllRange.SpecialCells(xlCellTypeFormulas)

If Not rConstRange Is Nothing And Not rFormRange Is Nothing Then
Set rAllRange = Union(rConstRange, rFormRange)
ElseIf Not rConstRange Is Nothing Then
Set rAllRange = rConstRange
ElseIf Not rFormRange Is Nothing Then
Set rAllRange = rFormRange
Else
MsgBox "Your selection is not valid", vbInformation
On Error GoTo 0
Exit Sub
End If

Application.Calculation = xlCalculationManual

For Each rCell In rAllRange
strAdd = rCell.Address
strAdd = rAllRange.Find(What:=rCell, After:=rCell,
LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Address

If strAdd < rCell.Address Then
rCell.Offset(0, -1).Value = "Duplicate"
End If
Next rCell

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
On Error GoTo 0
End Sub

In this particular one, the word "Selection" in "Set rAllRange =
Selection" (beginning of code) is highlighted and the error reads
"Compile error: Type Mismatch"

Any help would be greatly appreciated. I am truly stumped on this one.

 
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
Cannot Group that Selection error in PivotTable CherylS Excel Discussion (Misc queries) 1 June 16th 08 10:40 PM
Selection.Sort error Krager Excel Programming 3 September 3rd 05 06:12 PM
Strange or error : For each cl in Selection 'cl as range Jean-Yves[_2_] Excel Programming 0 March 1st 04 02:01 PM
Selection.ShapeRange.IncrementLeft error Anil Khemchandani Excel Programming 1 December 9th 03 09:29 PM
Selection.ShapeRange.IncrementLeft error Anil Khemchandani Excel Programming 0 December 9th 03 07:30 PM


All times are GMT +1. The time now is 04:13 AM.

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"