ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inserting a row (https://www.excelbanter.com/excel-programming/408049-inserting-row.html)

Scott Halper

Inserting a row
 
I have written some code in order to be able to lock the file but have
a macro insert a row when needed. I am having a problem because each
time the row is inserted it is hidden so I would like to have the new
adjusted row's rowheigh set so that it will be able to be seen. I
have posted my code so far below. Thanks in advance of your help.

I believe that the RowHeight has to be used in conjuction with the
Rows object. I'm just not sure how to have excel select the new
inserted row (which is directly above NFP_Insert). I thougth about
having it find the row number of NFP_Insert and then subtract one to
find the newly inserted row, however, I was unsuccessful at that as
well.

Private Sub NFP_Blank_Click()
Const PWORD As String = "123456"
Application.ScreenUpdating = False
With Worksheets("Southeast - NFP")
.Unprotect Password:=PWORD
.Range("Dist_Blank_NFP").Copy
.Range("NFP_Insert").Insert Shift:=xlUp
.RowHeight = 12.75
Application.CutCopyMode = False
.Range("Total_NFP").Select
.Protect Password:=PWORD
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Scott

joel

Inserting a row
 
the best way is to use offset

from
..RowHeight = 12.75

to
..Range("NFP_Insert").offset(-1,0).entirerow.RowHeight = 12.75


"Scott Halper" wrote:

I have written some code in order to be able to lock the file but have
a macro insert a row when needed. I am having a problem because each
time the row is inserted it is hidden so I would like to have the new
adjusted row's rowheigh set so that it will be able to be seen. I
have posted my code so far below. Thanks in advance of your help.

I believe that the RowHeight has to be used in conjuction with the
Rows object. I'm just not sure how to have excel select the new
inserted row (which is directly above NFP_Insert). I thougth about
having it find the row number of NFP_Insert and then subtract one to
find the newly inserted row, however, I was unsuccessful at that as
well.

Private Sub NFP_Blank_Click()
Const PWORD As String = "123456"
Application.ScreenUpdating = False
With Worksheets("Southeast - NFP")
.Unprotect Password:=PWORD
.Range("Dist_Blank_NFP").Copy
.Range("NFP_Insert").Insert Shift:=xlUp
.RowHeight = 12.75
Application.CutCopyMode = False
.Range("Total_NFP").Select
.Protect Password:=PWORD
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Scott



All times are GMT +1. The time now is 12:01 AM.

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