Trying to convert a string to integer getting error 13

vba317

Board Regular
Joined
Oct 7, 2015
Messages
58
I am trying to convert a string to an integer and I am getting an error 13 type mismatch. I am getting the error on the lNewColumn = CStr(sCol) line. I am inserting a new column in the spreadsheet. Than I am cutting another column into the newly inserted column. Finally I am trying to delete the original column that was cut from. Currently what is happening is the cutting and pasting is happening but the wrong column is getting deleted. I have tried a couple of different ways but I can't resolve this. any help is appreciated.


Code:
Dim lNewColumn As Long
Dim sNewColumn As String
    With Sheets("Data")
         If sCol <> "" Then
            .Range(sCol & "1").Value = sName
            'Insert new Q Column
            .Columns(sMoveCol).Insert Shift:=xlToRight
            'Cut and paste existing data and move it to Column Q
            Stop
            lNewColumn = CStr(sCol)
            lNewColumn = lNewColumn + 1
            sNewColumn = CStr(lNewColumn)
            .Columns(sNewColumn).Cut .Columns(sMoveCol)
            'Delete Old empty column
            .Columns(sCol).EntireColumn.Delete
         Else
            .Columns(sMoveCol).Insert Shift:=xlToRight
            .Range(sMoveCol & "1").Value = sName
        End If
    End With
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
This:
lNewColumn = CStr(sCol)

coerces sCol to be a string, not an integer. How is sCol dimensioned and what is its value when you reach the line above?
 
Upvote 0
Y is not a number and can't be coerced to one. You could use
Code:
.Cells(1, scol).entirecolumn.cut
instead.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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