Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Type Mismatch Error in Excel VBA when looping through worksheets

Check the FOR NEXT Loop - four lines into loop (see *****...)- getting
type mismatch error - any thoughts/advice appreciated. Just looping
though selecting columns and then two additional columns without the
headers. Eventually in order to change to Proper Case. Thanks! -
Scott

Application.ScreenUpdating = False
Dim myRng As Range
Dim myArea As Range
Dim wsSheet As Worksheet
On Error Resume Next

For Each wsSheet In Worksheets
wsSheet.Select
Set myRng = Range("D:D,E:E,I:I,J:J,N:N,O:O,P:P,Q:Q,Y2:Z2")
myRng.Select
' *********THESE NEXT TWO LINES WILL CAUSE THE ERROR 13 - TYPE
MISMATCH
myRng("Y2").Activate
myRng(Selection, Selection.End(xlDown)).Select

If myRng Is Nothing Then
MsgBox "Nothing in intersect range"
Else
For Each myArea In myRng.Areas
myArea.Formula = Application.Proper(myArea.Formula)
Next myArea
End If

Range("A1").Select
Next wsSheet

Application.ScreenUpdating = True

Sheets("Master").Select
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Type Mismatch Error in Excel VBA when looping through worksheets

myRng is a Range object which is set to contain 8 whole columns + 2 cells.
myRng("Y2") is syntactically incorrect - it didn't give me an error, but it
didn't do anything, either. Use Range("Y2") instead. You are using .Activate,
which is not the same thing as .Select, so your next statement is not doing
what you intended. Is your intent for column Y to select Y2 and extend the
selection down through all (contiguous) cells with data? If so, use

Range("Y2").Select
Range(Selection, Selection.End(xlDown)).Select

This will not add the selected cells in column Y to myRng, so you will need
to process this selection separately from myRng (maybe assign it to another
Range variable).

Because myRng has an assigned value, your "If myRng is Nothing" statement
will always be false. If you want to test if myRng contains anything, use
something like
If Application.WorksheetFunction.CountA(myRng) = 0 Then

Hope this helps,

Hutch

" wrote:

Check the FOR NEXT Loop - four lines into loop (see *****...)- getting
type mismatch error - any thoughts/advice appreciated. Just looping
though selecting columns and then two additional columns without the
headers. Eventually in order to change to Proper Case. Thanks! -
Scott

Application.ScreenUpdating = False
Dim myRng As Range
Dim myArea As Range
Dim wsSheet As Worksheet
On Error Resume Next

For Each wsSheet In Worksheets
wsSheet.Select
Set myRng = Range("D:D,E:E,I:I,J:J,N:N,O:O,P:P,Q:Q,Y2:Z2")
myRng.Select
' *********THESE NEXT TWO LINES WILL CAUSE THE ERROR 13 - TYPE
MISMATCH
myRng("Y2").Activate
myRng(Selection, Selection.End(xlDown)).Select

If myRng Is Nothing Then
MsgBox "Nothing in intersect range"
Else
For Each myArea In myRng.Areas
myArea.Formula = Application.Proper(myArea.Formula)
Next myArea
End If

Range("A1").Select
Next wsSheet

Application.ScreenUpdating = True

Sheets("Master").Select

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
runtime error 13 - type mismatch error in Excel 97 on Citrix Kevin Maher Excel Programming 7 March 8th 08 11:48 AM
Type Mismatch Error in Excel VB on RowIndex Rob Fenwick Excel Programming 1 February 17th 08 12:11 PM
Conditional Formatting - Run Time Error '13' Type Mismatch Error ksp Excel Programming 0 July 11th 06 07:06 AM
run time error(13) type mismatch in Excel Feed lorneg Excel Programming 0 May 22nd 06 10:33 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM


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