I am getting a type mismatch run time error with the following code.
Could someone tell me what I need to do differently?
Sub Macro2()
Dim MyRange As Range
Set MyRange = Range("L1:L15")
Do While Not IsEmpty(MyRange)
If MyRange > 1 Then
Range(MyRange.Offset(1, 0), MyRange.Offset(MyRange.Value - 1, _
0)).EntireColumn.Insert
Range(MyRange, MyRange.Offset(MyRange.Value - 1, 1)).EntireColumn.FillDown
End If
Set MyRange = MyRange.Offset(MyRange.Value, 0)
Loop
End Sub
It's in this line.
If MyRange > 1 Then
You are trying to compare a Range
object against a Numeric
value of 1.
What is your intent with that line? If you want to know values in each cell of that Range
, you'll have to write a loop.
It might be easier to loop through each cell in the range, assuming you are looking at the cell values:
Sub Macro2()
Dim MyRange As Range
Dim c as Cell
Set MyRange = Range("L1:L15")
For each c in MyRange.Cells
If c.Value > 1 Then
Range(c.Row, c.Column + 1).EntireColumn.Insert
Range(c.Row, c.Column + 1).EntireColumn.FillDown
End If
Next c
End Sub
I'm not clear on what you're trying to do in the middle there, so it may need some tweaking.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.