Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-04-2020, 01:23 AM
gavi12 gavi12 is offline A way to delete when 2nd column is empty Windows 10 A way to delete when 2nd column is empty Office 2016
Novice
A way to delete when 2nd column is empty
 
Join Date: Mar 2020
Posts: 4
gavi12 is on a distinguished road
Default A way to delete when 2nd column is empty

Hi

I am hoping someone will be able to help me. I have managed to put the code in which allows me to delete the code if the entire row is empty but would like to modify it if the 2nd column is empty it will delete as well.

I have attached a copy of the table so you can see what I am trying to do and any help would be appreciated as I have tried to manipulate it numerous ways.

Sub DeleteEmptyTablerowsandcolumns()
Application.ScreenUpdating = False
Dim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean
With ActiveDocument
For Each Tbl In .Tables
n = Tbl.Columns.Count


For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Columns(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Columns(i).Delete
Next i
Next Tbl
End With
With ActiveDocument
For Each Tbl In .Tables
n = Tbl.Rows.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Rows(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Rows(i).Delete
Next i
Next Tbl
End With
Set cel = Nothing: Set Tbl = Nothing
Application.ScreenUpdating = True
End Sub
Attached Images
File Type: jpg table example.JPG (37.1 KB, 21 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
A way to delete when 2nd column is empty Why i can not delete empty row in table? jaryszek Word Tables 2 06-28-2019 04:19 AM
Need to delete duplicate of a column B based on column A and keep ColumnB if unique value to columnA enigmaprince OneNote 0 08-23-2017 01:30 PM
A way to delete when 2nd column is empty Delete Empty Table Rows cltay87 Word VBA 4 02-27-2017 04:23 AM
A way to delete when 2nd column is empty Delete row with empty cel in a table vibor Word VBA 9 05-03-2015 05:42 AM
Creating VBA Code to Delete Empty Column in Table Faugs Word VBA 5 08-07-2014 03:29 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft