The below code is a small part of a large Sub; what the section does is a Row Count of the "Filtered" range and the "Temp" range.
What I’m try to do is; IF the “Filter” range is GREATER than the “Temp” range, increase the size of the “Temp” range to accommodate the “Filter” range, BUT the overriding caveat is that “Temp” range has to shift UP!!
(All variables needed/used for the below have been declared earlier)
But it is erroring out, "Run time error 1004 Insert method of Range class failed" on
Code I write to achieve what I’m after is usually grotesque and long winded but often as not with help I get to what I was trying to do, this is another case in point!
What I’m try to do is; IF the “Filter” range is GREATER than the “Temp” range, increase the size of the “Temp” range to accommodate the “Filter” range, BUT the overriding caveat is that “Temp” range has to shift UP!!
(All variables needed/used for the below have been declared earlier)
But it is erroring out, "Run time error 1004 Insert method of Range class failed" on
VBA Code:
Range("AK" & FrowTemp + 2 & ":AM" & LrowTemp - 1).Resize(Range("AP" & FrwD - 4).value).Insert Shift:=xlShiftUp
VBA Code:
' Next line does a Row Count of "VISIBLE" rows of the "Filter" range.
nrows = Range("AQ" & FrwD + 2 & ":AQ" & LrwD).SpecialCells(xlCellTypeVisible).Count 'This is the "Filtered" range
Range("AP" & FrwD - 3) = nrows 'This just places the row count in ("AP" & FrwD - 3)
' Next line does a Row Count of "Temp" range
nrows2 = Range("AK" & FrowTemp + 2 & ":AK" & LrowTemp - 1).Count 'This is the "Temp" range
Range("AP" & FrwD - 2) = nrows2 'This just places the row count in ("AP" & FrwD - 2)
x = Range("AP" & FrwD - 3) - Range("AP" & FrwD - 2)
Range("AP" & FrwD - 4) = x 'This just places the difference in the two Row Counts into ("AP" & FrwD - 4)
If nrows > nrows2 Then
MsgBox " Filter range is larger than Temp range "
Range("AK" & FrowTemp + 2 & ":AM" & LrowTemp - 1).Resize(Range("AP" & FrwD - 4).value).Insert Shift:=xlShiftUp
End If
>>>> continue rest of code
(Copy Filter range to Temp range………….)
Code I write to achieve what I’m after is usually grotesque and long winded but often as not with help I get to what I was trying to do, this is another case in point!