Type MisMatch Error

manthony

New Member
Joined
Dec 5, 2016
Messages
40
Hi, I am getting a type mismatch error on the code below in the "i = CLng(Cl.Value)" line. In a nutshell I have a formula in column AP that will give me a number or a blank. If a number then I am trying to offset/cut and paste the number down x rows (whatever the number value is) and over one column to column AQ. For example if in cell AP3 I have the number 6, then I would like the number 6 to be cut from cell AP3 and pasted into cell AQ9. The code below works only when I hard-code the number in but not when the number is there due to a formula. The problem seems to be in the " i = CLng(Cl.Value)" line. Any ideas?

Sub cutNpaste()
Dim Cl As Range, i As Long
For Each Cl In Columns("AQ").SpecialCells(xlCellTypeConstants, 23)

If Cl.Row > 1 Then
i = CLng(Cl.Value)
Cl.Cut Destination:=Cl.Offset(i, 1)
End If
Next Cl
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If any cell you are looping through has a formula returning "" (zero-length string) you will get a type mis-match - nullstrings are not capable of being coerced to a long data type. Try:

If Cl.Row > 1 Then
If Cl.Value <> "" then
i = CLng(Cl.Value)
Cl.Cut Destination:=Cl.Offset(i, 1)
End If
End If
 
Upvote 0

Forum statistics

Threads
1,202,976
Messages
6,052,882
Members
444,608
Latest member
Krunal_Shah

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