删除具有所有空单元格和标题的列

时间:2018-07-25 18:26:28

标签: excel vba excel-vba case

下面的代码删除整个列中所有空单元格的列。我需要对其进行更改,以删除整个列中所有空单元格的列,前提是存在列标题。我希望保留没有标题且没有单元格数据的列。

感谢您的帮助!

Dim X As Long, LastRow As Long, LastCol As Long
  LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  LastCol = Cells(1, Columns.count).End(xlToLeft).Column
  Application.ScreenUpdating = False
  For X = LastCol To 1 Step -1
    If Cells(1, X).Value = Join(Application.Transpose(Cells(1, X).Resize(LastRow)), "") Then Columns(X).Delete
  Next
  Application.ScreenUpdating = True

1 个答案:

答案 0 :(得分:0)

假设第1行是标题行...

    if(!empty($data) && is_array($data)){
        $columns = '';
        $values  = '';
        $i = 0;
        if(!array_key_exists('created',$data)){
            $data['created'] = date("Y-m-d H:i:s");
        }
        if(!array_key_exists('modified',$data)){
            $data['modified'] = date("Y-m-d H:i:s");
        }
        foreach($data as $key=>$val){
            $pre = ($i > 0)?', ':'';
            $columns .= $pre.$key;
            $values  .= $pre."'".$val."'";
                   $i++;
          }
        $query = "INSERT INTO ".$table." (".$columns.") VALUES (".$values.")";
        $insert = $this->db->query($query);


        return $insert?$this->db->insert_id:false;
    }else{
        return false;
    }
}