excel vba - Method 'Range' of object '_Global' failed. error -


i'm trying excel figure out columns of worksheet blank. idea delete blank columns. here's code have far:

sub macro2() ' ' macro2 macro ' dim totalcols integer dim totalrows integer  totalcols = activesheet.usedrange.columns.count totalrows = activesheet.usedrange.rows.count  dim integer dim j integer dim numnull integer  = 1 totalcols     j = 2 totalrows         dim location string         location = "r" & & ":" & "c" & j         if range(location).select = ""             numnull = numnull + 1         end if     next j     if numnull = totalrows - 1         msgbox ("column " & & "is null")     end if next  end sub 

at end checks see if numnull (number of null entries in row) = totalrows minus header. had working until statement if range(location).select = "". compiler says:

method 'range' of object '_global' failed

does know means or how can fix it?

your code using .select when should using .value

this might faster though:

sub tester()      dim col range, ur range     dim numrows long, numcols long, long, awf      set awf = application.worksheetfunction     set ur = activesheet.usedrange      numrows = ur.rows.count     numcols = ur.columns.count      'edit: account header row...     set ur = ur.offset(1,0).resize(numrows-1, numcols)     numrows = numrows - 1      = numcols 1 step -1         set col = ur.columns(i)         if awf.countblank(col) = numrows             msgbox "column #" & col.column & " empty"             'col.entirecolumn.delete         end if     next  end sub 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -