VBA script to delete all rows and columns except if specified columns have values

ceytl

Board Regular
Joined
Jun 6, 2009
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am looking for a VBA script that will let me delete all columns and rows except if columns F and G both have values in the same row.

They yellow highlighted rows are the ones I am trying to keep.

ACSST1Y2019.S0101-2021-05-14T170625.xlsx
ABCDEFG
1Under 5 years19,404,835±22,3145.9%±0.19,938,937±19,654
25 to 9 years19,690,437±69,2246.0%±0.110,033,518±51,101
310 to 14 years21,423,479±69,7796.5%±0.110,987,313±52,483
415 to 19 years21,353,524±36,1166.5%±0.110,903,653
520 to 24 years21,468,680±34,1956.5%±0.111,014,460
625 to 29 years23,233,299±29,9957.1%±0.111,817,829
730 to 34 years22,345,176±34,2176.8%±0.111,281,470
835 to 39 years21,728,259±61,7316.6%±0.110,892,040
940 to 44 years20,186,586±62,4106.1%±0.110,028,675
1045 to 49 years20,398,226±28,2756.2%±0.110,079,567
1150 to 54 years20,464,881±22,6426.2%±0.110,075,795
1255 to 59 years21,484,060±58,8296.5%±0.110,440,265
1360 to 64 years20,984,053±58,6436.4%±0.110,051,170±38,298
1465 to 69 years17,427,013±47,4205.3%±0.18,191,111±24,952
1570 to 74 years14,148,548±46,6734.3%±0.16,529,918±26,161
1675 to 79 years9,759,764±34,9843.0%±0.14,367,764
1780 to 84 years6,380,474±30,7131.9%±0.12,671,396±20,367
1885 years and over6,358,229±34,3211.9%±0.12,284,092±21,784
19SELECTED AGE CATEGORIES
205 to 14 years41,113,916±36,63612.5%±0.121,020,831±26,657
2115 to 17 years12,449,034±17,6813.8%±0.16,361,859±15,524
22Under 18 years72,967,785±33,14322.2%±0.137,321,627±29,379
2318 to 24 years30,373,170±42,2829.3%±0.115,556,254
2415 to 44 years130,315,524±37,16739.7%±0.165,938,127±31,255
2516 years and over263,534,161±52,16180.3%±0.1128,496,159±42,201
2618 years and over255,271,738±33,14377.8%±0.1124,267,346
2721 years and over241,886,206±83,33773.7%±0.1117,407,269±52,190
2860 years and over75,058,081±67,15922.9%±0.134,095,451±41,662
2962 years and over66,395,660±61,05420.2%±0.129,927,016±35,972
3065 years and over54,074,028±24,91516.5%±0.124,044,281
3175 years and over22,498,467±13,8626.9%±0.19,323,252±10,172
Data
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
If those cells in col G are completely empty how about
VBA Code:
Sub ceytl()
   Range("G:G").SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
If those cells in col G are completely empty how about
VBA Code:
Sub ceytl()
   Range("G:G").SpecialCells(xlBlanks).EntireRow.Delete
End Sub

Thanks!

Is there a way to leave the first row, and not delete that row?
 
Upvote 0
Yup, like
VBA Code:
Sub ceytl()
   Range("G2:G" & Rows.Count).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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