Fit rows

PIsabel

Board Regular
Joined
Feb 4, 2014
Messages
87
Hello.
I have this code to insert blank lines.
How can I indicate the size of the line when it is inserted?


VBA Code:
Sub blankrow
    'insere linhas brancas
    Dim Col As Variant
    Dim BlankRows As Long
    Dim LastRow As Long
    Dim R As Long
    Dim StartRow As Long

    Col = "x"
    StartRow = 1
    BlankRows = 1

    LastRow = Cells(Rows.Count, Col).End(xlUp).Row

    Application.ScreenUpdating = False

    With ActiveSheet
        For R = LastRow To StartRow + 1 Step -1
            If .Cells(R, Col) = "Diferente" Then
                .Cells(R, Col).EntireRow.Insert Shift:=xlDown
            End If
        Next R
    End With

    Application.ScreenUpdating = True

End sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,910
Office Version
  1. 365
Platform
  1. Windows
What do you mean by "the size of the line"?
One line would be one row.
 

kanadaaa

Active Member
Joined
Dec 29, 2019
Messages
341
Office Version
  1. 365
Platform
  1. Windows
Try this (you original code has quite some redundancies):
VBA Code:
Sub InsertRows()
    Dim lr As Long, i As Long
    lr = Cells(Rows.Count, "X").End(xlUp).Row
    
    Application.ScreenUpdating = False
    For i = lr To 1 Step -1
        If Cells(i, "X").Value = "Diferente" Then
            Cells(i, "X").EntireRow.Insert Shift:=xlDown
            Cells(i, "X").EntireRow.RowHeight = 40 'Change this to any height
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Solution

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,910
Office Version
  1. 365
Platform
  1. Windows
Ah, so it appears that maybe you were looking for how to set the height of the row.
Size can mean a number of different things, but that appears to make sense.
 

PIsabel

Board Regular
Joined
Feb 4, 2014
Messages
87
Thank you, it worked very well.
Forgive me for the mistake, it was not size but height
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,910
Office Version
  1. 365
Platform
  1. Windows
Thank you, it worked very well.
Forgive me for the mistake, it was not size but height
No worries.
I am glad that kanadaaa figured out what you meant and was able to answer it for you.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,380
Messages
5,635,919
Members
416,887
Latest member
SheriE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top