Variable Types - Help!

oakwood_001

Board Regular
Joined
Apr 4, 2008
Messages
108
Morning All,

I have a procedure that was working perfectly yesterday. I've not changed it and yet today it doesn't seem to be working.

I keep getting a 'Runtime Error '13', Type Mismatch' debug error. Can you help?

Code:
Public intRowCount As Integer
 
Sub mcrCopyDataNewSheet()
Dim strRawDataBook As String
Dim strNewBook As String
Dim strRawDataRange As String
    intRowCount = Range(Range("B5"), Range("B5").End(xlDown)).Count
    strRawDataBook = ActiveWorkbook.Name
    strRawDataRange = Application.InputBox(Prompt:="Please enter the Raw Data Range beginning with Earliest Start on Sunday and ending with the Saturday Rota:", Default:="L:AR", Type:=8)
    Range(strRawDataRange).Select
    Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    Range("1:1").Delete
    strNewBook = ActiveWorkbook.Name
    Workbooks(strRawDataBook).Activate
    Range(Range("B5"), Range("B5").End(xlDown)).Copy
    Workbooks(strNewBook).Activate
    Range("AK4").Select
    Selection.PasteSpecial Paste:=xlValues
End Sub

Any help, much appreciated. Driving me crazy :(
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Doesn't like Long either :confused:

And yet it works when I use...

Code:
    strRawDataRange = InputBox(Prompt:="Please enter the Raw Data Range beginning with Earliest Start on Sunday and ending with the Saturday Rota:", Default:="L:AR")

As oppose:

Code:
    strRawDataRange = Application.InputBox(Prompt:="Please enter the Raw Data Range beginning with Earliest Start on Sunday and ending with the Saturday Rota:", Default:="L:AR", Type:=8)
 
Upvote 0
Type:=8 specifies a range so you'd need to dim strRawDataRange as a Range variable to get it to work (or a Variant).
 
Upvote 0
And if you assign strRawDataRange as a range type you will need to use Set, eg

Code:
Set strRawDataRange = Application.InputBox(...

and then given it's now a defined range you can use:

Code:
strRawDataRange.Select

(and you might opt to rename it too)
 
Upvote 0
Me again...

I'm having the same problem with another piece of code where I get a 'Runtime '13'' error whereby it doesn't like having a cell entered as a range in an InputBox.

Code:
Sub mcrNamesToUniques()
Dim i As Integer
Dim n As Integer
Dim strStartingConCell As String
Dim strStartingUniqueCell As String
Dim strUnique As String
Dim strCon As String
Dim x As Integer
Dim y As Integer
Dim strOutputEIN As String

strStartingConCell = InputBox("Starting Concatenated Cell")
strStartingUniqueCell = InputBox("Starting Unique Cell")
Application.ScreenUpdating = False
y = Range(Range(strStartingConCell), Range(strStartingConCell).End(xlDown)).Count
x = Range(Range(strStartingUniqueCell), Range(strStartingUniqueCell).End(xlDown)).Count
For n = 0 To x
For i = 0 To y
    strCon = Range(strStartingConCell).Offset(i, 0).Value
    strUnique = Range(strStartingUniqueCell).Offset(n, 0).Value
        If strCon = strUnique Then
            strOutputEIN = Range(strStartingConCell).Offset(i, 2).Value
            Range(strStartingUniqueCell).Offset(n, 200).Select
            Selection.End(xlToLeft).Select
            ActiveCell.Offset(0, 1).Value = strOutputEIN
        Else
        End If
Next i
Next n
Application.ScreenUpdating = True
End Sub

And yet when I 'step into' the procedure it works fine. If I try to run it fully however, it won't work and I get the error.

And this was all working fine yesterday. Is there a setting or something that could have been changed whereby it won't work now?

It's completely baffling.

Thanks.
 
Upvote 0
Top tip: if you tell us which line is causing the problem, it saves us having to try and guess... :)
 
Upvote 0
Yeh that would help :stickouttounge:

Code:
    strCon = Range(strStartingConCell).Offset(i, 0).Value

Thats the line where the Runtime error first appears

And yet stepping through it handles that line fine and performs perfectly
 
Upvote 0
And to reiterate anything that holds a row count or row reference should really always be a Long type as opposed to an Integer type... Integer stops at 32767 so if you try to assign a number > than that to the variable it will bug.
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top