excel - Copy a range of cells and only select cells with data -


I am looking for a way to copy a boundary of a cell, but only to copy those cells that There is a value. / P>

In my Excel sheet I have data running from A1-A18, B is empty and C1-C2 is. Now I want to copy all those cells which have a value. / Pre>

It will copy everything from the A1-C50, but I should be copying the A1-A18 and C1-C2, although these include data but it needs to be made in a way That is, when I have data of B or My limit, they will also be copied.

  'Therefore the limit can be 5000 and it only selects the data range with the range ("A1") with the range (.cell (1, 1), end ( (5000, 3) Call., Copy and End   

Thanks!

  Sub-testing ( ) I like the integer sheet ("Sheet1"). Select the I = 1 with the range ("A1") if. (1, 1) .value = "" then the Else range (.seel (1 , 1). End (XL DOWN) Copy Destination: = Sheets ("Sheet2"). Range ("A" & I) x = X + 1 end if ends with sheets ("Sheet1"). Select X = 1 with range ("B1") 'column B may be empty. If so, then xlDown cell C65536 will return 'And the entire blank column will be copied ... stop it if .sele (1, 1) value = "" then nothing in this column. "Do not do anything. Range (" b "& amp; i ) X = x + 1 termination ends with sheets ("(" ("b" and (i) x = x + 1 end (sheet 2) sheet 1 "). Select x = 1 with range (" C1 "). If (1, 1). Property =" " R. Else Range (.seel (1, 1), end (XL DOWN). Copy Destination: = Sheets ("Sheet2"). Range ("C" & amp; i) x = x + 1 End & End End End End   

A1 - A5 contains data, A6 Blank, A7 data It stops at A6 and stays above column B, and continues in the same way.

Columns have different sizes, the safest thing is to copy them one by one . Due to any shortcuts La Lights, you will probably lose the possibility of headache. With the class ("B1" empty.If yes, then xlDown cell C65536 will return 'and the entire blank column will be copied ... stop it .sec (1, 1). Value = "" Then' this Nothing in the column. 'Do nothing. Else Range (. (1, 1)., End (XLDown)). End my Destination Range with the B & IF Copy Range ("C1") range. ((1 , 1). End (xlDown). Copy MyDestinationRangeC

Now it's ugly, and for a loop through a cleaner option column If you have multiple columns, especially if you have many columns and you are sticking them in the adjacent columns in the same order, you have several columns with long loops or worksheets ("Sheet 1") through columns for ICol = 1 to 3 Check if the column is not blank if cell (1, 1). Value = "" then nothing in this column. "Do nothing. Copy the other column to the destination category." (1, 1)., End (XL DOWN) copy _ destination: = worksheet ("sheet 2 ") .Column (iCol) .Cell (1, 1) End if the next ICol End Sub


Finish with Edit, so that you changed your question .. Try looping through individual cells, check whether the existing cell is empty or not, and if there is no copy it is not. It has not been tested, but you get this idea:

  iMaxRow = 5000 'or whatever is the maximum' Do not be too big because it will slow down your code 'from ICol = 1 3 'for loop' iRol = 1 to 3 'through columns and rows, or in many columns you have iMaxRow ("Sheet 1") with worksheets for iRow = 1. Cell (iRow, iCol) 'The cell is not empty. If .Value = "" Do nothing 'in this cell, then do nothing. Otherwise copy the cell to the destination. Copy Destination: = Worksheet ("Sheet 2"). Cells (iRow, iCol) end if the next IRO ends with IOC   

This code will actually be slower if iMaxRow is bigger my garbage That you are trying to solve a problem in a way that is inefficiently ... When there is a change in questions then it is a bit difficult to settle on an optimal strategy.

Comments