Fit rows

PIsabel

Board Regular
Joined
Feb 4, 2014
Messages
118
Office Version
  1. 365
Platform
  1. Windows
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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
What do you mean by "the size of the line"?
One line would be one row.
 
Upvote 0
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
 
Upvote 0
Solution
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.
 
Upvote 0
Thank you, it worked very well.
Forgive me for the mistake, it was not size but height
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

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
Back
Top