ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   inserting in wrong location (https://www.excelbanter.com/excel-worksheet-functions/236447-inserting-wrong-location.html)

Tami

inserting in wrong location
 
hi.
Can someone review the below code and suggest what i need to change to get
the macro to insert the range name " sample_style" where the cursor was at
the time the macro button was pressed. Currently, the macro inserts the
"sample style", beneath the "sample_style" range.
thanks in advance for any advice.
thx

If MsgBox("Do you want to insert a new style at your cursor", vbYesNo +
vbDefaultButton2) = vbYes Then

ActiveCell.EntireRow

Range("sample_style").Select
Selection.Copy
ActiveCell.EntireRow.Insert Shift:=xlDown
Else
Exit Sub
End If
End Sub

Jacob Skaria

inserting in wrong location
 
Tami, try the below and feedback

If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
ActiveCell.EntireRow.Insert Shift:=xlDown
Rows(Range("sample_style").Row).Copy Rows(ActiveCell.Row)
End If

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

hi.
Can someone review the below code and suggest what i need to change to get
the macro to insert the range name " sample_style" where the cursor was at
the time the macro button was pressed. Currently, the macro inserts the
"sample style", beneath the "sample_style" range.
thanks in advance for any advice.
thx

If MsgBox("Do you want to insert a new style at your cursor", vbYesNo +
vbDefaultButton2) = vbYes Then

ActiveCell.EntireRow

Range("sample_style").Select
Selection.Copy
ActiveCell.EntireRow.Insert Shift:=xlDown
Else
Exit Sub
End If
End Sub


Tami

inserting in wrong location
 
yeah, finally some progress!!....it did insert one line...but "sample_style"
actually consists of 4 lines...the macro only copied/inserted the first
line...any suggestions, Jacob?

"Jacob Skaria" wrote:

Tami, try the below and feedback

If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
ActiveCell.EntireRow.Insert Shift:=xlDown
Rows(Range("sample_style").Row).Copy Rows(ActiveCell.Row)
End If

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

hi.
Can someone review the below code and suggest what i need to change to get
the macro to insert the range name " sample_style" where the cursor was at
the time the macro button was pressed. Currently, the macro inserts the
"sample style", beneath the "sample_style" range.
thanks in advance for any advice.
thx

If MsgBox("Do you want to insert a new style at your cursor", vbYesNo +
vbDefaultButton2) = vbYes Then

ActiveCell.EntireRow

Range("sample_style").Select
Selection.Copy
ActiveCell.EntireRow.Insert Shift:=xlDown
Else
Exit Sub
End If
End Sub


Jacob Skaria

inserting in wrong location
 
Hi Tami

Try the below..

Application.ScreenUpdating = False
If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
Range("sample_style").Copy
ActiveCell.Insert Shift:=xlDown
Application.CutCopyMode = False
End If
Application.ScreenUpdating = True

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

yeah, finally some progress!!....it did insert one line...but "sample_style"
actually consists of 4 lines...the macro only copied/inserted the first
line...any suggestions, Jacob?

"Jacob Skaria" wrote:

Tami, try the below and feedback

If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
ActiveCell.EntireRow.Insert Shift:=xlDown
Rows(Range("sample_style").Row).Copy Rows(ActiveCell.Row)
End If

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

hi.
Can someone review the below code and suggest what i need to change to get
the macro to insert the range name " sample_style" where the cursor was at
the time the macro button was pressed. Currently, the macro inserts the
"sample style", beneath the "sample_style" range.
thanks in advance for any advice.
thx

If MsgBox("Do you want to insert a new style at your cursor", vbYesNo +
vbDefaultButton2) = vbYes Then

ActiveCell.EntireRow

Range("sample_style").Select
Selection.Copy
ActiveCell.EntireRow.Insert Shift:=xlDown
Else
Exit Sub
End If
End Sub


Tami

inserting in wrong location
 
Nice!! Worked like a charm!

Do you mind briefly describing what the screen updating code does, just so i
can apply it later, if applicable?

"Jacob Skaria" wrote:

Hi Tami

Try the below..

Application.ScreenUpdating = False
If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
Range("sample_style").Copy
ActiveCell.Insert Shift:=xlDown
Application.CutCopyMode = False
End If
Application.ScreenUpdating = True

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

yeah, finally some progress!!....it did insert one line...but "sample_style"
actually consists of 4 lines...the macro only copied/inserted the first
line...any suggestions, Jacob?

"Jacob Skaria" wrote:

Tami, try the below and feedback

If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
ActiveCell.EntireRow.Insert Shift:=xlDown
Rows(Range("sample_style").Row).Copy Rows(ActiveCell.Row)
End If

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

hi.
Can someone review the below code and suggest what i need to change to get
the macro to insert the range name " sample_style" where the cursor was at
the time the macro button was pressed. Currently, the macro inserts the
"sample style", beneath the "sample_style" range.
thanks in advance for any advice.
thx

If MsgBox("Do you want to insert a new style at your cursor", vbYesNo +
vbDefaultButton2) = vbYes Then

ActiveCell.EntireRow

Range("sample_style").Select
Selection.Copy
ActiveCell.EntireRow.Insert Shift:=xlDown
Else
Exit Sub
End If
End Sub


Jacob Skaria

inserting in wrong location
 
Tami, turn screen updating off to speed up your macro code. You won't be able
to see what the macro is doing, but it will run faster. Turn it off and
try..to see the difference.

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

Nice!! Worked like a charm!

Do you mind briefly describing what the screen updating code does, just so i
can apply it later, if applicable?

"Jacob Skaria" wrote:

Hi Tami

Try the below..

Application.ScreenUpdating = False
If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
Range("sample_style").Copy
ActiveCell.Insert Shift:=xlDown
Application.CutCopyMode = False
End If
Application.ScreenUpdating = True

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

yeah, finally some progress!!....it did insert one line...but "sample_style"
actually consists of 4 lines...the macro only copied/inserted the first
line...any suggestions, Jacob?

"Jacob Skaria" wrote:

Tami, try the below and feedback

If MsgBox("Do you want to insert a new style at your cursor", _
vbYesNo + vbDefaultButton2) = vbYes Then
ActiveCell.EntireRow.Insert Shift:=xlDown
Rows(Range("sample_style").Row).Copy Rows(ActiveCell.Row)
End If

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

hi.
Can someone review the below code and suggest what i need to change to get
the macro to insert the range name " sample_style" where the cursor was at
the time the macro button was pressed. Currently, the macro inserts the
"sample style", beneath the "sample_style" range.
thanks in advance for any advice.
thx

If MsgBox("Do you want to insert a new style at your cursor", vbYesNo +
vbDefaultButton2) = vbYes Then

ActiveCell.EntireRow

Range("sample_style").Select
Selection.Copy
ActiveCell.EntireRow.Insert Shift:=xlDown
Else
Exit Sub
End If
End Sub



All times are GMT +1. The time now is 10:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com