So whenever I need the .Insert in the future ( such as part of a code when answering a thread) , I shall copy my Function after any code and then replace the line
rng.Insert xlShift_____
with
Call AlnWonkShtIst(rng, ______ )
I think that makes no sense enough. And will look forward to any comments, however rude and appropriately / deservingly insulting.
Thank you for watching.
Jack
_..............................................
Codes:
Calling Demo Code for Calling Function
Public Function AlnWonkShtIst(ARangeArea As Range, ShtSpread As Variant)
http://www.excelforum.com/showthread...t=#post4371552
' Call Code For Function AlnWonkShtIst in Thread
' VBA Range.Insert Method ( Excel OOP Syntax Error )
Sub MyTestsInsert() ' MyTestsInsert.. well not quite... but at least to End stop, if she can take it..... ;)
Rem 1) Worksheets Info
Dim ws As Worksheet: Set ws = ActiveSheet: Set ws = Worksheets("Inserting") 'CHANGE SHEET NAME TO SUIT YOURS
ws.Cells.Clear
Dim rng As Range: Set rng = ws.Range("D10:D12")
'Arbritrary initilal sheet values
Let rng.Value = "Anythink"
Application.Wait (Now + TimeValue("0:00:05"))
Dim vOriginalValues As Variant: Let vOriginalValues = rng.Value 'Back up for origninal Range Values
'Demo code part start===================================
Rem 2) Demo for .Insert ... :=Accross Shift
Let rng.Value = "Original Range here" 'Effectively these are the original values when calling the Function in the Practice.
ws.Columns.AutoFit
Application.Wait (Now + TimeValue("0:00:05"))
Call AlnWonkShtIst(rng, -4121)
'Normal End point of Function, showing values as "Original Range here" in new position
Application.Wait (Now + TimeValue("0:00:05"))
Let rng.Value = "Original range is here now"
Application.Wait (Now + TimeValue("0:00:05"))
ws.Cells.Clear 'Clear for next demo
'Arbritrary initilal sheet values
Let rng.Value = "Anythink"
Application.Wait (Now + TimeValue("0:00:05"))
Let vOriginalValues = rng.Value 'Back up for origninal Range Values
Rem 5) Demo for .Insert ... :=Down Shift
Let rng.Value = "Original Range here" 'Effectively these are the original values when calling the Function in the Practice.
ws.Columns.AutoFit
Application.Wait (Now + TimeValue("0:00:05"))
Call AlnWonkShtIst(rng, "d")
'Normal End point of Function, showing values as "Original Range here" in new position
Application.Wait (Now + TimeValue("0:00:05"))
Let rng.Value = "Original range is here now"
Application.Wait (Now + TimeValue("0:00:05"))
'End demo Code part----------------------------------------
Rem 10) Demo over Put back original values back in sheet
If IsArray(vOriginalValues) Then 'Orignal Range may be 1 or more cells so .Value property my retunn 1 or a field of Values
Let rng.Value = vOriginalValues
Else ' For 1 cell , put single value back in
Let rng.Value = vOriginalValues
End If
End Sub
_......................................
Now here The called ( by above code )
Function
http://www.excelforum.com/showthread...t=#post4371553
'
'
' Function for Thread VBA Range.Insert Method ( Excel OOP Syntax Error )
' Alternative for VBA Range.Insert Method
'
'
Public Function AlnWonkShtIst(ARangeArea As Range, ShtSpread As Variant) 'ShtSpread:= "Right" , "R" , "r" or -4121 "Down" , "D" , "d" or xlShiftDown -4121 Shift cells down. xlShiftToRight -4161 Shift cells to the right. xlDown -4121 Down. xlToLeft -4159 To left. xlToRight -4161 To right. xlUp -4162 Up.
' ARangeArea is to be used as a Template / Pattern to say where and what size to create a New Virgin Range
' ShtSpread is some argument to specify which direction to spread aside to make space for the new Virgin Range object
Dim MiVrginRnge As Range, OrigRange As Range ' New Virgin Range, Original Range used as template and necerssarily shifted by the AlnWonkShtIst Function ( VBA .Insert Method )
Set OrigRange = ARangeArea
Rem 3) .Insert ... :=Accross Shift Demo 1
If CStr(ShtSpread) = "Right" Or CStr(ShtSpread) = "R" Or CStr(ShtSpread) = "r" Or CStr(ShtSpread) = "-4121" Then
ARangeArea.Insert xlShiftToRight
Set MiVrginRnge = ARangeArea.Offset(0, (-1 * ARangeArea.Columns.Count))
Rem 5) .Insert ... :=Down Shift Demo 2
Else
ARangeArea.Insert xlShiftDown
Set MiVrginRnge = ARangeArea.Offset((-1 * ARangeArea.Rows.Count), 0)
End If
Rem - RamSham 69) ' Bit of dialogue, Wait a bit ;) , Shut up again....................... If the Excel kids are United, United United, United we Satnd, United we Fall , We will never be divided. This 'aint no Love Song neither , it is for real, man : http://www.mrexcel.com/forum/lounge-v-2-0/929097-artificial-general-intelligence.html#post4466440
Dim vOrigRangeDotValue As Variant: Let vOrigRangeDotValue = OrigRange.Value 'Orignal Range may be 1 or more cells so .Value property my retunn 1 or a field of Values
If IsArray(vOrigRangeDotValue) Then
Let ARangeArea.Value = "Original Range Shifted 'ere"
Let MiVrginRnge.Value = "New Virgin range" ' "VBA Shooting out for intercepts" for single value "unorientetd" Array will result in this going in all Original Range Cells, even for more than one.
MiVrginRnge.Parent.Columns.AutoFit
Application.Wait (Now + TimeValue("0:00:05"))
Let OrigRange.Value = vOrigRangeDotValue
Else
Dim OrigRangeValue As String: Let OrigRangeValue = OrigRange.Value
Let OrigRange.Value = "Original Range Shifted 'ere"
Let MiVrginRnge.Value = "New Virgin range" ' "VBA Shooting out for intercepts" for single value "unorientetd" Array will result in this going in all Original Range Cells, even for more than one.
Application.Wait (Now + TimeValue("0:00:05"))
Let OrigRange.Value = OrigRangeValue
End If
'MiVrginRnge.Clear
End Function
' https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.insert.aspx
' https://msdn.microsoft.com/de-de/library/office/ff840310.aspx
' XlInsertShiftDirection-Enumeration (Excel)
' xlShiftDown -4121 Zellen nach unten verschieben
' xlShiftToRight -4161 Zellen nach rechts verschieben
Bookmarks