Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Error 13 Type Mismatch

This code is to hide the entire row if the cell in column D is empty.

This code returns the Type MisMatch error:

Sub hideme()
Application.ScreenUpdating = False
Dim myrange As Range, myrange1 As Range
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
Set myrange = Range("D4:D" & lastrow)
For Each c In myrange
If c.Value = "" Then
If myrange1 Is Nothing Then
Set myrange1 = c.EntireRow
Else
Set myrange1 = Union(myrange1, c.EntireRow)
End If
End If
Next
myrange1.EntireRow.Hidden = True
End Sub

It also does work in my 2003 version but doesn't in the 2007... anyone know
why this is?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Error 13 Type Mismatch

Is this a case of substituting :

If c.Value = "" Then

for

If IsEmpty(c.Value) Then

"Justin" wrote:

This code is to hide the entire row if the cell in column D is empty.

This code returns the Type MisMatch error:

Sub hideme()
Application.ScreenUpdating = False
Dim myrange As Range, myrange1 As Range
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
Set myrange = Range("D4:D" & lastrow)
For Each c In myrange
If c.Value = "" Then
If myrange1 Is Nothing Then
Set myrange1 = c.EntireRow
Else
Set myrange1 = Union(myrange1, c.EntireRow)
End If
End If
Next
myrange1.EntireRow.Hidden = True
End Sub

It also does work in my 2003 version but doesn't in the 2007... anyone know
why this is?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Error 13 Type Mismatch

Justin,

I tweaked your code a little and the code below worked just fine for me in
2007. I would also recommend making sure you set the ScreenUpdating property
back to True at the end of your code.

Option Explicit

Sub HideRows()

Dim myRange As Range
Dim myRange1 As Range
Dim LastRow As Long
Dim c As Range

Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, "D").End(xlUp).Row
Set myRange = Range("D4:D" & LastRow)

For Each c In myRange
If Trim(c.Value) = "" Then
If myRange1 Is Nothing Then
Set myRange1 = c.EntireRow
Else
Set myRange1 = Union(myRange1, c.EntireRow)
End If
End If
Next c

myRange1.EntireRow.Hidden = True

Application.ScreenUpdating = True

End Sub

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"Justin" wrote:

This code is to hide the entire row if the cell in column D is empty.

This code returns the Type MisMatch error:

Sub hideme()
Application.ScreenUpdating = False
Dim myrange As Range, myrange1 As Range
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
Set myrange = Range("D4:D" & lastrow)
For Each c In myrange
If c.Value = "" Then
If myrange1 Is Nothing Then
Set myrange1 = c.EntireRow
Else
Set myrange1 = Union(myrange1, c.EntireRow)
End If
End If
Next
myrange1.EntireRow.Hidden = True
End Sub

It also does work in my 2003 version but doesn't in the 2007... anyone know
why this is?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Error 13 Type Mismatch

Thanks for replying.... So it gives me the same error run I ran what you had,
however, I created a new workbook places some random values into column D
then ran the macro and everything worked fine. So im not sure what is going
on with it. Can you think of anything esle?

Thanks

Justin

"Ryan H" wrote:

Justin,

I tweaked your code a little and the code below worked just fine for me in
2007. I would also recommend making sure you set the ScreenUpdating property
back to True at the end of your code.

Option Explicit

Sub HideRows()

Dim myRange As Range
Dim myRange1 As Range
Dim LastRow As Long
Dim c As Range

Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, "D").End(xlUp).Row
Set myRange = Range("D4:D" & LastRow)

For Each c In myRange
If Trim(c.Value) = "" Then
If myRange1 Is Nothing Then
Set myRange1 = c.EntireRow
Else
Set myRange1 = Union(myRange1, c.EntireRow)
End If
End If
Next c

myRange1.EntireRow.Hidden = True

Application.ScreenUpdating = True

End Sub

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"Justin" wrote:

This code is to hide the entire row if the cell in column D is empty.

This code returns the Type MisMatch error:

Sub hideme()
Application.ScreenUpdating = False
Dim myrange As Range, myrange1 As Range
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
Set myrange = Range("D4:D" & lastrow)
For Each c In myrange
If c.Value = "" Then
If myrange1 Is Nothing Then
Set myrange1 = c.EntireRow
Else
Set myrange1 = Union(myrange1, c.EntireRow)
End If
End If
Next
myrange1.EntireRow.Hidden = True
End Sub

It also does work in my 2003 version but doesn't in the 2007... anyone know
why this is?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error 13 Type Mismatch

If you have errors (like #n/a or #div/0!) in your cells, you'll get this error.

Maybe...

For Each c In myRange
if iserror(c.value) then
'skip it???
else
If Trim(c.Value) = "" Then
If myRange1 Is Nothing Then
Set myRange1 = c.EntireRow
Else
Set myRange1 = Union(myRange1, c.EntireRow)
End If
End If
end if
Next c

If this doesn't help, what line causes the error?

Maybe adding a line to show the address would help:

For Each c In myRange
msgbox c.address(0,0)
If Trim(c.Value) = "" Then
If myRange1 Is Nothing Then
Set myRange1 = c.EntireRow
Else
Set myRange1 = Union(myRange1, c.EntireRow)
End If
End If
Next c

Ryan H wrote:

Justin,

I tweaked your code a little and the code below worked just fine for me in
2007. I would also recommend making sure you set the ScreenUpdating property
back to True at the end of your code.

Option Explicit

Sub HideRows()

Dim myRange As Range
Dim myRange1 As Range
Dim LastRow As Long
Dim c As Range

Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, "D").End(xlUp).Row
Set myRange = Range("D4:D" & LastRow)

For Each c In myRange
If Trim(c.Value) = "" Then
If myRange1 Is Nothing Then
Set myRange1 = c.EntireRow
Else
Set myRange1 = Union(myRange1, c.EntireRow)
End If
End If
Next c

myRange1.EntireRow.Hidden = True

Application.ScreenUpdating = True

End Sub

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan

"Justin" wrote:

This code is to hide the entire row if the cell in column D is empty.

This code returns the Type MisMatch error:

Sub hideme()
Application.ScreenUpdating = False
Dim myrange As Range, myrange1 As Range
lastrow = Cells(Rows.Count, "D").End(xlUp).Row
Set myrange = Range("D4:D" & lastrow)
For Each c In myrange
If c.Value = "" Then
If myrange1 Is Nothing Then
Set myrange1 = c.EntireRow
Else
Set myrange1 = Union(myrange1, c.EntireRow)
End If
End If
Next
myrange1.EntireRow.Hidden = True
End Sub

It also does work in my 2003 version but doesn't in the 2007... anyone know
why this is?


--

Dave Peterson
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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
runtime error 13 - type mismatch error in Excel 97 on Citrix Kevin Maher Excel Programming 7 March 8th 08 11:48 AM
Conditional Formatting - Run Time Error '13' Type Mismatch Error ksp Excel Programming 0 July 11th 06 07:06 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM


All times are GMT +1. The time now is 09:28 AM.

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

About Us

"It's about Microsoft Excel"