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


I am new to learning how to program with VBA and Excel. This code came
from the book, “VBA for Excel Made Simple” that I borrowed from the
library. When I run the code, I keep getting the error message: Run-time
error '13': Type mismatch.

The purpose of this form is to insert an extra row and add the
representative name in the RepName list.

I have also attached the sample excel file and the explanation that
came from the actual book. Thank you for all your help in advance.


Code:
--------------------

Private Sub UserForm_Initialize()
RepBox = ""
SalesBox = "0"
For Each Cell In Range("rep_name")
RepList.AddItem Cell.Value
Next
End Sub

Private Sub AddButton_Click()
RepBox.SetFocus
With RepBox
If .Value = "" Then
MsgBox "Enter a name for the rep to be added"
.SetFocus
End If
If .Value = "" Then
MsgBox "Enter a sales value for the rep given"
SalesBox.SetFocus
End If
End With
With Worksheets("weeklysales").Range("total")
newSumSales = SalesBox.Value + .Offset(0, 1)
.EntireRow.Insert
.Offset(-1, 0) = RepBox.Value
.Offset(-1, 1) = SalesBox.Value
.Offset(0, 1) = newSumSales
Range("sales_to_date", .Offset(-1, 1)).Name = "sales_to_date"
End With
RepList.AddItem RepBox.Value
Unload Me
End Sub

Private Sub CancelButton_Click()
Unload Me
End
End Sub

--------------------


+-------------------------------------------------------------------+
|Filename: SALESMAN.xls |
|Download: http://www.thecodecage.com/forumz/attachment.php?attachmentid=75|
+-------------------------------------------------------------------+

--
siamadu
------------------------------------------------------------------------
siamadu's Profile: http://www.thecodecage.com/forumz/member.php?userid=128
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=63314

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time error '13': Type mismatch


Firstly you should qualify all your statements and set your objects
properly adding Me. in front of RepBox etc is a must.
Private Sub UserForm_Initialize()
Me.RepBox = ""
Me.SalesBox = "0"
For Each Cell In Range("rep_name")
Me.RepList.AddItem Cell.Value
Next
End Sub
Private Sub AddButton_Click()
Me.RepBox.SetFocus
With Me.RepBox
If .Value = "" Then
MsgBox "Enter a name for the rep to be added"
..SetFocus
End If
If .Value = "" Then
MsgBox "Enter a sales value for the rep given"
SalesBox.SetFocus
End If
End With
With Worksheets("weeklysales").Range("total")
newSumSales = Me.SalesBox.Value + .Offset(0, 1)
..EntireRow.Insert
..Offset(-1, 0) = RepBox.Value
..Offset(-1, 1) = SalesBox.Value
..Offset(0, 1) = newSumSales
Range("sales_to_date", .Offset(-1, 1)).Name = "sales_to_date"
End With
Me.RepList.AddItem Me.RepBox.Value
Unload Me
End Sub
Private Sub CancelButton_Click()
Unload Me
End
End Sub

Secondly in your workbook you do not have a range or declared variable
for newSumSales!

siamadu;227505 Wrote:
I am new to learning how to program with VBA and Excel. This code came
from the book, “VBA for Excel Made Simple” that I borrowed from the
library. When I run the code, I keep getting the error message: Run-time
error '13': Type mismatch.

The purpose of this form is to insert an extra row and add the
representative name in the RepName list.

I have also attached the sample excel file and the explanation that
came from the actual book. Thank you for all your help in advance.


Code:
--------------------

Private Sub UserForm_Initialize()
RepBox = ""
SalesBox = "0"
For Each Cell In Range("rep_name")
RepList.AddItem Cell.Value
Next
End Sub

Private Sub AddButton_Click()
RepBox.SetFocus
With RepBox
If .Value = "" Then
MsgBox "Enter a name for the rep to be added"
.SetFocus
End If
If .Value = "" Then
MsgBox "Enter a sales value for the rep given"
SalesBox.SetFocus
End If
End With
With Worksheets("weeklysales").Range("total")
newSumSales = SalesBox.Value + .Offset(0, 1)
.EntireRow.Insert
.Offset(-1, 0) = RepBox.Value
.Offset(-1, 1) = SalesBox.Value
.Offset(0, 1) = newSumSales
Range("sales_to_date", .Offset(-1, 1)).Name = "sales_to_date"
End With
RepList.AddItem RepBox.Value
Unload Me
End Sub

Private Sub CancelButton_Click()
Unload Me
End
End Sub

--------------------



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=63314

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 cellist Excel Programming 7 February 8th 09 01:30 PM
Run Time error 13 type mismatch cellist Excel Programming 2 February 8th 09 02:06 AM
run-time error 13: Type mismatch? Marko Enula Excel Discussion (Misc queries) 2 February 5th 08 01:00 PM
Run Time Error 13 Type Mismatch ExcelMonkey Excel Programming 3 October 12th 05 12:51 PM
run time error 13 type mismatch kkknie[_170_] Excel Programming 0 July 20th 04 03:28 PM


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