Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default MSGBOX Run-time Error '13': Type mismatch

I receive a Run-time Error '13': Type mismatch on the "MsgBox" statement
shown below. Before continuing with the use of the "sourceRange" I just want
to ensure
that I am picking up the correct data.

I am even wondering however if the line prior to the MsgBox, "Set
sourceRange..." is actually working.

Any suggestions to correct the type mismatch and display the actual values
within the source range?


Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then
For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
MsgBox sourceRange 'I even tried "MsgBox sourceRange.value"
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default MSGBOX Run-time Error '13': Type mismatch

Hi,

sourceRange is working fine and on the first pass through the loop it is
'Set' to A8:D8 i.e. 4 cells each of which may or may not have a value in. I
say that because the only thing your code actually establishes is that there
is something in column 3 (C) in row 8 or higher.

You're getting a type mismatch because sourceRange doesn't have a default
value but you can test it is working by using sourceRange.address for example

If you change your code to this you can loop thriugh sourcerange and see the
values

Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then

For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
For Each c In sourceRange
MsgBox c.Value 'I even tried "MsgBox sourceRange.value"
Next
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub



--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"GEdwards" wrote:

I receive a Run-time Error '13': Type mismatch on the "MsgBox" statement
shown below. Before continuing with the use of the "sourceRange" I just want
to ensure
that I am picking up the correct data.

I am even wondering however if the line prior to the MsgBox, "Set
sourceRange..." is actually working.

Any suggestions to correct the type mismatch and display the actual values
within the source range?


Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then
For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
MsgBox sourceRange 'I even tried "MsgBox sourceRange.value"
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default MSGBOX Run-time Error '13': Type mismatch

This small change works great.

Many thanks to you Mike.

"Mike H" wrote:

Hi,

sourceRange is working fine and on the first pass through the loop it is
'Set' to A8:D8 i.e. 4 cells each of which may or may not have a value in. I
say that because the only thing your code actually establishes is that there
is something in column 3 (C) in row 8 or higher.

You're getting a type mismatch because sourceRange doesn't have a default
value but you can test it is working by using sourceRange.address for example

If you change your code to this you can loop thriugh sourcerange and see the
values

Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then

For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
For Each c In sourceRange
MsgBox c.Value 'I even tried "MsgBox sourceRange.value"
Next
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub



--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"GEdwards" wrote:

I receive a Run-time Error '13': Type mismatch on the "MsgBox" statement
shown below. Before continuing with the use of the "sourceRange" I just want
to ensure
that I am picking up the correct data.

I am even wondering however if the line prior to the MsgBox, "Set
sourceRange..." is actually working.

Any suggestions to correct the type mismatch and display the actual values
within the source range?


Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then
For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
MsgBox sourceRange 'I even tried "MsgBox sourceRange.value"
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default MSGBOX Run-time Error '13': Type mismatch

Your welcome and thank you for the feedback
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"GEdwards" wrote:

This small change works great.

Many thanks to you Mike.

"Mike H" wrote:

Hi,

sourceRange is working fine and on the first pass through the loop it is
'Set' to A8:D8 i.e. 4 cells each of which may or may not have a value in. I
say that because the only thing your code actually establishes is that there
is something in column 3 (C) in row 8 or higher.

You're getting a type mismatch because sourceRange doesn't have a default
value but you can test it is working by using sourceRange.address for example

If you change your code to this you can loop thriugh sourcerange and see the
values

Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then

For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
For Each c In sourceRange
MsgBox c.Value 'I even tried "MsgBox sourceRange.value"
Next
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub



--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"GEdwards" wrote:

I receive a Run-time Error '13': Type mismatch on the "MsgBox" statement
shown below. Before continuing with the use of the "sourceRange" I just want
to ensure
that I am picking up the correct data.

I am even wondering however if the line prior to the MsgBox, "Set
sourceRange..." is actually working.

Any suggestions to correct the type mismatch and display the actual values
within the source range?


Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then
For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
MsgBox sourceRange 'I even tried "MsgBox sourceRange.value"
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default MSGBOX Run-time Error '13': Type mismatch

sourceRange is a range object and cannot be displayed in Msgbox...You need to
loop through the values like the below

Dim cell As range, strMsg As String
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
For each cell in sourceRange
strMsg = strMsg & "," & cell.Text
Next
Msgbox strMsg


--
Jacob (MVP - Excel)


"GEdwards" wrote:

I receive a Run-time Error '13': Type mismatch on the "MsgBox" statement
shown below. Before continuing with the use of the "sourceRange" I just want
to ensure
that I am picking up the correct data.

I am even wondering however if the line prior to the MsgBox, "Set
sourceRange..." is actually working.

Any suggestions to correct the type mismatch and display the actual values
within the source range?


Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then
For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
MsgBox sourceRange 'I even tried "MsgBox sourceRange.value"
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default MSGBOX Run-time Error '13': Type mismatch

Thanks Jacob, this works well too by displaying the range contents all in 1
line.

"Jacob Skaria" wrote:

sourceRange is a range object and cannot be displayed in Msgbox...You need to
loop through the values like the below

Dim cell As range, strMsg As String
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
For each cell in sourceRange
strMsg = strMsg & "," & cell.Text
Next
Msgbox strMsg


--
Jacob (MVP - Excel)


"GEdwards" wrote:

I receive a Run-time Error '13': Type mismatch on the "MsgBox" statement
shown below. Before continuing with the use of the "sourceRange" I just want
to ensure
that I am picking up the correct data.

I am even wondering however if the line prior to the MsgBox, "Set
sourceRange..." is actually working.

Any suggestions to correct the type mismatch and display the actual values
within the source range?


Sub DisplayMat()
Dim sourceRange As Range

RowCount = 8
lastrow = Cells(Rows.Count, 3).End(xlUp).Row
If lastrow 7 Then
For Each qty In Range("A8:A" & lastrow)
If qty < "" Then
Set sourceRange = Range("A" & RowCount & ":" & "D" & RowCount)
MsgBox sourceRange 'I even tried "MsgBox sourceRange.value"
'Do more stuff here with the sourceRange and output to another WSheet
End If
RowCount = RowCount + 1
Next
End If
End Sub

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
Run time error 13 - type mismatch KG Old Wolf Excel Programming 6 September 27th 09 07:36 PM
Run-time error '13': Type mismatch siamadu Excel Programming 1 April 15th 09 11:41 AM
Run Time Error 13- Type mismatch Ram B Excel Programming 4 July 21st 08 04:04 PM
run time error 13 type mismatch Glenda Excel Programming 3 October 24th 07 04:40 AM
Run Time Error '13' Type mismatch David Adamson[_3_] Excel Programming 2 June 10th 04 04:00 AM


All times are GMT +1. The time now is 06:56 PM.

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"