Delete Blank Lines (ROWS)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am having trouble getting this code to work the way I want it to.
It currently deletes blank lines, but is deleting the blanks in between lines, which I do not want to happen. I want the blank lines in between the populated rows and everything after the last populated cell in Column G
to be deleted. Can some one help me. I have added a picture to help. The highlighted yellow cells need to remain, I want to delete the lines colored blue.
Public Sub DeleteBlankLines()
' Declaring the variables
Dim WS As Worksheet
Dim UncWs As Worksheet, RepWs As Worksheet, ImpWs As Worksheet
Dim StopAtData As Boolean
Dim UserAnswer As Variant
Dim rngDelete As Range, UncDelete As Range, RepDelete As Range, ImpDelete As Range
Dim RowDeleteCount As Integer
'Set Worksheets
Set UncWs = ThisWorkbook.Sheets("Uncertainty")
Set RepWs = ThisWorkbook.Sheets("Repeatability")
Set WS = ThisWorkbook.Sheets("Datasheet")
Set ImpWs = ThisWorkbook.Sheets("Import Map")
'Set Delete Variables to Nothing
Set rngDelete = Nothing
Set UncDelete = Nothing
Set RepDelete = Nothing
Set ImpDelete = Nothing
RowDeleteCount = 0
'Determine which cells to delete
UserAnswer = MsgBox("Do you want to delete empty rows " & _
"outside of your data?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
StopAtData = True
'Not needed Turn off at Call in Form
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
'Application.EnableEvents = False
' Set Range
DS_LastRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
For CurrentRow = DS_StartRow To DS_LastRow Step 1
' Delete blank rows by checking the value of cell in column G (Nominal Value)
With WS.Range("G" & CurrentRow & ":O" & CurrentRow)
If WorksheetFunction.CountBlank(.Cells) >= 9 Then
If rngDelete Is Nothing Then
Set rngDelete = WS.Rows(CurrentRow)
Set UncDelete = UncWs.Rows(CurrentRow)
Set RepDelete = RepWs.Rows(CurrentRow)
Set ImpDelete = ImpWs.Rows(CurrentRow)
RowDeleteCount = 1
Else
Set rngDelete = Union(rngDelete, WS.Rows(CurrentRow))
Set UncDelete = Union(UncDelete, UncWs.Rows(CurrentRow))
Set RepDelete = Union(RepDelete, RepWs.Rows(CurrentRow))
Set ImpDelete = Union(ImpDelete, ImpWs.Rows(CurrentRow))
RowDeleteCount = RowDeleteCount + 1
End If
End If
End With
Next CurrentRow
Else
Exit Sub
End If
'Refresh UsedRange (if necessary)
If RowDeleteCount > 0 Then
UserAnswer = MsgBox("This will Delete " & RowDeleteCount & " rows, Do you want to delete empty rows?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
' Delete blank rows
If Not rngDelete Is Nothing Then
UncWs.Unprotect ("$1mco")
RepWs.Unprotect ("$1mco")
rngDelete.EntireRow.Delete Shift:=xlUp
UncDelete.EntireRow.Delete Shift:=xlUp
RepDelete.EntireRow.Delete Shift:=xlUp
ImpDelete.EntireRow.Delete Shift:=xlUp
UncWs.Protect "$1mco", , , , , True, True
RepWs.Protect ("$1mco")
End If
Else
MsgBox "No Rows will be Deleted.", vbInformation, "No Rows Deleted"
End If
Else
MsgBox "No blank rows were found!", vbInformation, "No Blanks Found"
End If
' Set New Last Row Moved to Event
DS_LastRow = WS.Range("G7:G" & WS.Rows.Count).End(xlUp).Row
'Not needed Turn on at Call in Form
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
'Application.EnableEvents = True
End Sub
excel vba excel-vba
add a comment |
I am having trouble getting this code to work the way I want it to.
It currently deletes blank lines, but is deleting the blanks in between lines, which I do not want to happen. I want the blank lines in between the populated rows and everything after the last populated cell in Column G
to be deleted. Can some one help me. I have added a picture to help. The highlighted yellow cells need to remain, I want to delete the lines colored blue.
Public Sub DeleteBlankLines()
' Declaring the variables
Dim WS As Worksheet
Dim UncWs As Worksheet, RepWs As Worksheet, ImpWs As Worksheet
Dim StopAtData As Boolean
Dim UserAnswer As Variant
Dim rngDelete As Range, UncDelete As Range, RepDelete As Range, ImpDelete As Range
Dim RowDeleteCount As Integer
'Set Worksheets
Set UncWs = ThisWorkbook.Sheets("Uncertainty")
Set RepWs = ThisWorkbook.Sheets("Repeatability")
Set WS = ThisWorkbook.Sheets("Datasheet")
Set ImpWs = ThisWorkbook.Sheets("Import Map")
'Set Delete Variables to Nothing
Set rngDelete = Nothing
Set UncDelete = Nothing
Set RepDelete = Nothing
Set ImpDelete = Nothing
RowDeleteCount = 0
'Determine which cells to delete
UserAnswer = MsgBox("Do you want to delete empty rows " & _
"outside of your data?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
StopAtData = True
'Not needed Turn off at Call in Form
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
'Application.EnableEvents = False
' Set Range
DS_LastRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
For CurrentRow = DS_StartRow To DS_LastRow Step 1
' Delete blank rows by checking the value of cell in column G (Nominal Value)
With WS.Range("G" & CurrentRow & ":O" & CurrentRow)
If WorksheetFunction.CountBlank(.Cells) >= 9 Then
If rngDelete Is Nothing Then
Set rngDelete = WS.Rows(CurrentRow)
Set UncDelete = UncWs.Rows(CurrentRow)
Set RepDelete = RepWs.Rows(CurrentRow)
Set ImpDelete = ImpWs.Rows(CurrentRow)
RowDeleteCount = 1
Else
Set rngDelete = Union(rngDelete, WS.Rows(CurrentRow))
Set UncDelete = Union(UncDelete, UncWs.Rows(CurrentRow))
Set RepDelete = Union(RepDelete, RepWs.Rows(CurrentRow))
Set ImpDelete = Union(ImpDelete, ImpWs.Rows(CurrentRow))
RowDeleteCount = RowDeleteCount + 1
End If
End If
End With
Next CurrentRow
Else
Exit Sub
End If
'Refresh UsedRange (if necessary)
If RowDeleteCount > 0 Then
UserAnswer = MsgBox("This will Delete " & RowDeleteCount & " rows, Do you want to delete empty rows?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
' Delete blank rows
If Not rngDelete Is Nothing Then
UncWs.Unprotect ("$1mco")
RepWs.Unprotect ("$1mco")
rngDelete.EntireRow.Delete Shift:=xlUp
UncDelete.EntireRow.Delete Shift:=xlUp
RepDelete.EntireRow.Delete Shift:=xlUp
ImpDelete.EntireRow.Delete Shift:=xlUp
UncWs.Protect "$1mco", , , , , True, True
RepWs.Protect ("$1mco")
End If
Else
MsgBox "No Rows will be Deleted.", vbInformation, "No Rows Deleted"
End If
Else
MsgBox "No blank rows were found!", vbInformation, "No Blanks Found"
End If
' Set New Last Row Moved to Event
DS_LastRow = WS.Range("G7:G" & WS.Rows.Count).End(xlUp).Row
'Not needed Turn on at Call in Form
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
'Application.EnableEvents = True
End Sub
excel vba excel-vba
2
If by "the lines coloured blue" you mean the empty rows below your data, then that's now how Excel works. If you really don't want to see them, you can always hide them but you can't remove them
– cybernetic.nomad
Jan 4 at 18:35
When you say column G, you mean all lines where G is empty or something else?
– VBasic2008
Jan 4 at 18:40
I want the blank rows in column G that are highlighted yellow to stay and the ones below the last populated cell in G to be removed
– Zack Thompson
Jan 4 at 18:43
add a comment |
I am having trouble getting this code to work the way I want it to.
It currently deletes blank lines, but is deleting the blanks in between lines, which I do not want to happen. I want the blank lines in between the populated rows and everything after the last populated cell in Column G
to be deleted. Can some one help me. I have added a picture to help. The highlighted yellow cells need to remain, I want to delete the lines colored blue.
Public Sub DeleteBlankLines()
' Declaring the variables
Dim WS As Worksheet
Dim UncWs As Worksheet, RepWs As Worksheet, ImpWs As Worksheet
Dim StopAtData As Boolean
Dim UserAnswer As Variant
Dim rngDelete As Range, UncDelete As Range, RepDelete As Range, ImpDelete As Range
Dim RowDeleteCount As Integer
'Set Worksheets
Set UncWs = ThisWorkbook.Sheets("Uncertainty")
Set RepWs = ThisWorkbook.Sheets("Repeatability")
Set WS = ThisWorkbook.Sheets("Datasheet")
Set ImpWs = ThisWorkbook.Sheets("Import Map")
'Set Delete Variables to Nothing
Set rngDelete = Nothing
Set UncDelete = Nothing
Set RepDelete = Nothing
Set ImpDelete = Nothing
RowDeleteCount = 0
'Determine which cells to delete
UserAnswer = MsgBox("Do you want to delete empty rows " & _
"outside of your data?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
StopAtData = True
'Not needed Turn off at Call in Form
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
'Application.EnableEvents = False
' Set Range
DS_LastRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
For CurrentRow = DS_StartRow To DS_LastRow Step 1
' Delete blank rows by checking the value of cell in column G (Nominal Value)
With WS.Range("G" & CurrentRow & ":O" & CurrentRow)
If WorksheetFunction.CountBlank(.Cells) >= 9 Then
If rngDelete Is Nothing Then
Set rngDelete = WS.Rows(CurrentRow)
Set UncDelete = UncWs.Rows(CurrentRow)
Set RepDelete = RepWs.Rows(CurrentRow)
Set ImpDelete = ImpWs.Rows(CurrentRow)
RowDeleteCount = 1
Else
Set rngDelete = Union(rngDelete, WS.Rows(CurrentRow))
Set UncDelete = Union(UncDelete, UncWs.Rows(CurrentRow))
Set RepDelete = Union(RepDelete, RepWs.Rows(CurrentRow))
Set ImpDelete = Union(ImpDelete, ImpWs.Rows(CurrentRow))
RowDeleteCount = RowDeleteCount + 1
End If
End If
End With
Next CurrentRow
Else
Exit Sub
End If
'Refresh UsedRange (if necessary)
If RowDeleteCount > 0 Then
UserAnswer = MsgBox("This will Delete " & RowDeleteCount & " rows, Do you want to delete empty rows?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
' Delete blank rows
If Not rngDelete Is Nothing Then
UncWs.Unprotect ("$1mco")
RepWs.Unprotect ("$1mco")
rngDelete.EntireRow.Delete Shift:=xlUp
UncDelete.EntireRow.Delete Shift:=xlUp
RepDelete.EntireRow.Delete Shift:=xlUp
ImpDelete.EntireRow.Delete Shift:=xlUp
UncWs.Protect "$1mco", , , , , True, True
RepWs.Protect ("$1mco")
End If
Else
MsgBox "No Rows will be Deleted.", vbInformation, "No Rows Deleted"
End If
Else
MsgBox "No blank rows were found!", vbInformation, "No Blanks Found"
End If
' Set New Last Row Moved to Event
DS_LastRow = WS.Range("G7:G" & WS.Rows.Count).End(xlUp).Row
'Not needed Turn on at Call in Form
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
'Application.EnableEvents = True
End Sub
excel vba excel-vba
I am having trouble getting this code to work the way I want it to.
It currently deletes blank lines, but is deleting the blanks in between lines, which I do not want to happen. I want the blank lines in between the populated rows and everything after the last populated cell in Column G
to be deleted. Can some one help me. I have added a picture to help. The highlighted yellow cells need to remain, I want to delete the lines colored blue.
Public Sub DeleteBlankLines()
' Declaring the variables
Dim WS As Worksheet
Dim UncWs As Worksheet, RepWs As Worksheet, ImpWs As Worksheet
Dim StopAtData As Boolean
Dim UserAnswer As Variant
Dim rngDelete As Range, UncDelete As Range, RepDelete As Range, ImpDelete As Range
Dim RowDeleteCount As Integer
'Set Worksheets
Set UncWs = ThisWorkbook.Sheets("Uncertainty")
Set RepWs = ThisWorkbook.Sheets("Repeatability")
Set WS = ThisWorkbook.Sheets("Datasheet")
Set ImpWs = ThisWorkbook.Sheets("Import Map")
'Set Delete Variables to Nothing
Set rngDelete = Nothing
Set UncDelete = Nothing
Set RepDelete = Nothing
Set ImpDelete = Nothing
RowDeleteCount = 0
'Determine which cells to delete
UserAnswer = MsgBox("Do you want to delete empty rows " & _
"outside of your data?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
StopAtData = True
'Not needed Turn off at Call in Form
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
'Application.EnableEvents = False
' Set Range
DS_LastRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
For CurrentRow = DS_StartRow To DS_LastRow Step 1
' Delete blank rows by checking the value of cell in column G (Nominal Value)
With WS.Range("G" & CurrentRow & ":O" & CurrentRow)
If WorksheetFunction.CountBlank(.Cells) >= 9 Then
If rngDelete Is Nothing Then
Set rngDelete = WS.Rows(CurrentRow)
Set UncDelete = UncWs.Rows(CurrentRow)
Set RepDelete = RepWs.Rows(CurrentRow)
Set ImpDelete = ImpWs.Rows(CurrentRow)
RowDeleteCount = 1
Else
Set rngDelete = Union(rngDelete, WS.Rows(CurrentRow))
Set UncDelete = Union(UncDelete, UncWs.Rows(CurrentRow))
Set RepDelete = Union(RepDelete, RepWs.Rows(CurrentRow))
Set ImpDelete = Union(ImpDelete, ImpWs.Rows(CurrentRow))
RowDeleteCount = RowDeleteCount + 1
End If
End If
End With
Next CurrentRow
Else
Exit Sub
End If
'Refresh UsedRange (if necessary)
If RowDeleteCount > 0 Then
UserAnswer = MsgBox("This will Delete " & RowDeleteCount & " rows, Do you want to delete empty rows?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
' Delete blank rows
If Not rngDelete Is Nothing Then
UncWs.Unprotect ("$1mco")
RepWs.Unprotect ("$1mco")
rngDelete.EntireRow.Delete Shift:=xlUp
UncDelete.EntireRow.Delete Shift:=xlUp
RepDelete.EntireRow.Delete Shift:=xlUp
ImpDelete.EntireRow.Delete Shift:=xlUp
UncWs.Protect "$1mco", , , , , True, True
RepWs.Protect ("$1mco")
End If
Else
MsgBox "No Rows will be Deleted.", vbInformation, "No Rows Deleted"
End If
Else
MsgBox "No blank rows were found!", vbInformation, "No Blanks Found"
End If
' Set New Last Row Moved to Event
DS_LastRow = WS.Range("G7:G" & WS.Rows.Count).End(xlUp).Row
'Not needed Turn on at Call in Form
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
'Application.EnableEvents = True
End Sub
excel vba excel-vba
excel vba excel-vba
edited Jan 4 at 18:33
cybernetic.nomad
3,02121222
3,02121222
asked Jan 4 at 18:30
Zack ThompsonZack Thompson
93
93
2
If by "the lines coloured blue" you mean the empty rows below your data, then that's now how Excel works. If you really don't want to see them, you can always hide them but you can't remove them
– cybernetic.nomad
Jan 4 at 18:35
When you say column G, you mean all lines where G is empty or something else?
– VBasic2008
Jan 4 at 18:40
I want the blank rows in column G that are highlighted yellow to stay and the ones below the last populated cell in G to be removed
– Zack Thompson
Jan 4 at 18:43
add a comment |
2
If by "the lines coloured blue" you mean the empty rows below your data, then that's now how Excel works. If you really don't want to see them, you can always hide them but you can't remove them
– cybernetic.nomad
Jan 4 at 18:35
When you say column G, you mean all lines where G is empty or something else?
– VBasic2008
Jan 4 at 18:40
I want the blank rows in column G that are highlighted yellow to stay and the ones below the last populated cell in G to be removed
– Zack Thompson
Jan 4 at 18:43
2
2
If by "the lines coloured blue" you mean the empty rows below your data, then that's now how Excel works. If you really don't want to see them, you can always hide them but you can't remove them
– cybernetic.nomad
Jan 4 at 18:35
If by "the lines coloured blue" you mean the empty rows below your data, then that's now how Excel works. If you really don't want to see them, you can always hide them but you can't remove them
– cybernetic.nomad
Jan 4 at 18:35
When you say column G, you mean all lines where G is empty or something else?
– VBasic2008
Jan 4 at 18:40
When you say column G, you mean all lines where G is empty or something else?
– VBasic2008
Jan 4 at 18:40
I want the blank rows in column G that are highlighted yellow to stay and the ones below the last populated cell in G to be removed
– Zack Thompson
Jan 4 at 18:43
I want the blank rows in column G that are highlighted yellow to stay and the ones below the last populated cell in G to be removed
– Zack Thompson
Jan 4 at 18:43
add a comment |
2 Answers
2
active
oldest
votes
maybe something like,
dim lr as long
with ThisWorkbook.Sheets("Datasheet")
lr = .cells.find(what:="*", after:=.cells(1), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlprevious).row
.usedrange.offset(lr, 0).entirerow.clear
end with
add a comment |
Delete Below Last Row
Deletes all data below the last used row in a column.
The Code
'*******************************************************************************
' Purpose: Deletes all data below the last used row of a specified column.
'*******************************************************************************
Sub DeleteBelowLastRow()
Const cVntSheet As Variant = "Sheet1" ' Worksheet Name/Index
Const cVntColumn As Variant = "G" ' Last Row Column Letter/Number
Dim lngLastRow As Long ' Last Row
With ThisWorkbook.Worksheets(cVntSheet)
lngLastRow = .Cells(.Rows.Count, cVntColumn).End(xlUp).Row
.Range(.Cells(lngLastRow + 1, 1), .Cells(.Rows.Count, 1)) _
.EntireRow.Delete
End With
End Sub
'*******************************************************************************
@user10862412: In his last comment!?
– VBasic2008
Jan 4 at 19:11
Sorry, I didn't catch that comment.
– user10862412
Jan 4 at 19:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54044299%2fdelete-blank-lines-rows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
maybe something like,
dim lr as long
with ThisWorkbook.Sheets("Datasheet")
lr = .cells.find(what:="*", after:=.cells(1), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlprevious).row
.usedrange.offset(lr, 0).entirerow.clear
end with
add a comment |
maybe something like,
dim lr as long
with ThisWorkbook.Sheets("Datasheet")
lr = .cells.find(what:="*", after:=.cells(1), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlprevious).row
.usedrange.offset(lr, 0).entirerow.clear
end with
add a comment |
maybe something like,
dim lr as long
with ThisWorkbook.Sheets("Datasheet")
lr = .cells.find(what:="*", after:=.cells(1), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlprevious).row
.usedrange.offset(lr, 0).entirerow.clear
end with
maybe something like,
dim lr as long
with ThisWorkbook.Sheets("Datasheet")
lr = .cells.find(what:="*", after:=.cells(1), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlprevious).row
.usedrange.offset(lr, 0).entirerow.clear
end with
answered Jan 4 at 18:40
user10862412user10862412
4123
4123
add a comment |
add a comment |
Delete Below Last Row
Deletes all data below the last used row in a column.
The Code
'*******************************************************************************
' Purpose: Deletes all data below the last used row of a specified column.
'*******************************************************************************
Sub DeleteBelowLastRow()
Const cVntSheet As Variant = "Sheet1" ' Worksheet Name/Index
Const cVntColumn As Variant = "G" ' Last Row Column Letter/Number
Dim lngLastRow As Long ' Last Row
With ThisWorkbook.Worksheets(cVntSheet)
lngLastRow = .Cells(.Rows.Count, cVntColumn).End(xlUp).Row
.Range(.Cells(lngLastRow + 1, 1), .Cells(.Rows.Count, 1)) _
.EntireRow.Delete
End With
End Sub
'*******************************************************************************
@user10862412: In his last comment!?
– VBasic2008
Jan 4 at 19:11
Sorry, I didn't catch that comment.
– user10862412
Jan 4 at 19:13
add a comment |
Delete Below Last Row
Deletes all data below the last used row in a column.
The Code
'*******************************************************************************
' Purpose: Deletes all data below the last used row of a specified column.
'*******************************************************************************
Sub DeleteBelowLastRow()
Const cVntSheet As Variant = "Sheet1" ' Worksheet Name/Index
Const cVntColumn As Variant = "G" ' Last Row Column Letter/Number
Dim lngLastRow As Long ' Last Row
With ThisWorkbook.Worksheets(cVntSheet)
lngLastRow = .Cells(.Rows.Count, cVntColumn).End(xlUp).Row
.Range(.Cells(lngLastRow + 1, 1), .Cells(.Rows.Count, 1)) _
.EntireRow.Delete
End With
End Sub
'*******************************************************************************
@user10862412: In his last comment!?
– VBasic2008
Jan 4 at 19:11
Sorry, I didn't catch that comment.
– user10862412
Jan 4 at 19:13
add a comment |
Delete Below Last Row
Deletes all data below the last used row in a column.
The Code
'*******************************************************************************
' Purpose: Deletes all data below the last used row of a specified column.
'*******************************************************************************
Sub DeleteBelowLastRow()
Const cVntSheet As Variant = "Sheet1" ' Worksheet Name/Index
Const cVntColumn As Variant = "G" ' Last Row Column Letter/Number
Dim lngLastRow As Long ' Last Row
With ThisWorkbook.Worksheets(cVntSheet)
lngLastRow = .Cells(.Rows.Count, cVntColumn).End(xlUp).Row
.Range(.Cells(lngLastRow + 1, 1), .Cells(.Rows.Count, 1)) _
.EntireRow.Delete
End With
End Sub
'*******************************************************************************
Delete Below Last Row
Deletes all data below the last used row in a column.
The Code
'*******************************************************************************
' Purpose: Deletes all data below the last used row of a specified column.
'*******************************************************************************
Sub DeleteBelowLastRow()
Const cVntSheet As Variant = "Sheet1" ' Worksheet Name/Index
Const cVntColumn As Variant = "G" ' Last Row Column Letter/Number
Dim lngLastRow As Long ' Last Row
With ThisWorkbook.Worksheets(cVntSheet)
lngLastRow = .Cells(.Rows.Count, cVntColumn).End(xlUp).Row
.Range(.Cells(lngLastRow + 1, 1), .Cells(.Rows.Count, 1)) _
.EntireRow.Delete
End With
End Sub
'*******************************************************************************
edited Jan 4 at 19:02
answered Jan 4 at 18:57
VBasic2008VBasic2008
3,5372517
3,5372517
@user10862412: In his last comment!?
– VBasic2008
Jan 4 at 19:11
Sorry, I didn't catch that comment.
– user10862412
Jan 4 at 19:13
add a comment |
@user10862412: In his last comment!?
– VBasic2008
Jan 4 at 19:11
Sorry, I didn't catch that comment.
– user10862412
Jan 4 at 19:13
@user10862412: In his last comment!?
– VBasic2008
Jan 4 at 19:11
@user10862412: In his last comment!?
– VBasic2008
Jan 4 at 19:11
Sorry, I didn't catch that comment.
– user10862412
Jan 4 at 19:13
Sorry, I didn't catch that comment.
– user10862412
Jan 4 at 19:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54044299%2fdelete-blank-lines-rows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
If by "the lines coloured blue" you mean the empty rows below your data, then that's now how Excel works. If you really don't want to see them, you can always hide them but you can't remove them
– cybernetic.nomad
Jan 4 at 18:35
When you say column G, you mean all lines where G is empty or something else?
– VBasic2008
Jan 4 at 18:40
I want the blank rows in column G that are highlighted yellow to stay and the ones below the last populated cell in G to be removed
– Zack Thompson
Jan 4 at 18:43