Quantcast
Viewing all articles
Browse latest Browse all 451

Remove columns if the number of rows is less than a certain number using vba Excel

I have an Excel file with a lot of columns. I want to create a loop (B1:LastCol) using vba that goes through the amount of filled columns, and that deletes the columns that contain less than a certain numbers of rows (for example, columns with less than 50 rows will be removed as they are incomplete measurements).I am not sure how I can handle this. I included some corrupt code, to give a better idea of what I want.

Sub test() Dim LastColNr As Long Dim LastCol As String LastColNr = Graphs.Cells(1, Columns.Count).End(xlToLeft).Column LastCol = GetColumnLetter(LastColNr) MsgBox "Column Count: " & LastColNr  & LastCol Dim cel As Range Dim rng As Range For Each rng In Range("B1: LastCol").Columns     If rng("B1", rng("B1").End(xlDown)).Rows.Count > 50       Column.Delete     End If Next rngEnd Sub

Viewing all articles
Browse latest Browse all 451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>