简体   繁体   中英

VBA Copy only non blank cells

does anyone one how to instead of static range:

 '~~> Copy the range
    wsI.Range("A1:K50").Copy

To change it to dynamic where A1:A50 is calculated depending on non-blank cells.

So if Sheet1 has 23 lines and the rest of them are blank so range would be: A1:K23?

just in case someone looks for an answer:

issue - when copying data from other sheet where I had formulas, pasted cells are blank, but not actually blank. It holds some sort of 'nothing'...

  • solution ,SpecialCells(xlCellTypeVisible).Copy to copy data and paste in the same workbook with Paste:=xlPasteValuesAndNumberFormats (it holds date value as this was something I needed). Then used "find and replace" code to clear "blank, but not blank" cells.

'~~> Find "" and replace with pneumonoultramicroscopicsilicovolcanoconiosis

Worksheets("paste").Range("A1:K500").Cells.Replace What:="", Replacement:="pneumonoultramicroscopicsilicovolcanoconiosis", LookAt:= _
    xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

'~~> Find pneumonoultramicroscopicsilicovolcanoconiosis and replace with ""

Worksheets("paste").Range("A1:K500").Cells.Replace What:="pneumonoultramicroscopicsilicovolcanoconiosis", Replacement:="", LookAt:= _
    xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM