excel - Looping until blank column -


i putting vba code think needs loop. loops biggest weakness vba , need assistance.

i have text file import excel spreadsheet. length of how many columns , rows , down vary day day. example today's file might have data in columns - h, tomorrow might : p. each typical row count around 200 mark, not long.

in essence im trying make 1 long list in column data spread on multiple columns. im looking loop checks if column has data in it, if copies data bottom of data in column a. illustration purposes data goes out column g, copy b1, xl down, find first empty row in , paste, same c, stopping after column g.

i hope i’ve been clear when writing this. in advance matt

you first want loop on columns. loop column b lastcolumn (which there function for.) want loop through rows within column find first empty row, , substract 1 arrive @ last column data.

 if cells(row,col) = ""    lastrowcopy = row -1 

then want copy a1, , keep track of last row posted in. want have variable counts. like:

lastrowpaste = lastrowpaste + row 

i write code it, perhaps learn more figuring out yourself.

edit: perhaps interesting read on finding last rows , or columns this: http://www.rondebruin.nl/win/s9/win005.htm

edit2: ofcourse use same finding last column method used finding last row. loop through columns , see if:

if cells(1, col) = ""  lastcol = col -1 

edit3:

i wrote out entire code:

sub copypaste()  dim lastrowcopy string dim lastrowpaste string dim lastcol string dim col integer dim row integer  lastcol = activesheet.usedrange.columns.count lastrowcopy = activesheet.usedrange.rows.count lastrowpaste = activesheet.usedrange.rows.count  row = 1 lastrowpaste     if cells(row, 1) = ""          lastrowpaste = row          exit     end if next row   col = 2 lastcol        if application.worksheetfunction.counta(columns(col)) = 0             lastcol = col -1        end if next col  col = 2 lastcol     row = 1 lastrowcopy         if not cells(row, col) = ""             cells(lastrowpaste, 1) = cells(row, col)             lastrowpaste = lastrowpaste + 1         end if     next row next col   end sub 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -