请指导如何在Excel 2007中完全删除UsedRange? [英] Please guide how to completely delete UsedRange in Excel 2007?

查看:153
本文介绍了请指导如何在Excel 2007中完全删除UsedRange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Excel 2007进行数据分析  MACRO。  因为我想得到一张表的列数, 我选择 获取它的Activsheet.UsedRange.Column.Count。 请按以下方式查找脚本:

I'm working on a data analysis MACRO via Excel 2007.   Since I want to get the columns count of one sheet,  I choose  Activsheet.UsedRange.Column.Count to get it.  Please find the script as following lines:

//开始

xlsSheetContinuousServiceVertical.Activate

    intColumnCount_ContinuousService_Vertical = xlsSheetContinuousServiceVertical.UsedRange.Columns.Count

    strLastColumnName_ContinuousService_Vertical = Split(xlsSheetContinuousServiceVertical.Cells(1,intColumnCount_ContinuousService_Vertical).Address," $")(1)

   xlsSheetContinuousServiceVertical.Columns(" A:"& strLastColumnName_ContinuousService_Vertical)。删除(xlShiftToLeft)

xlsSheetContinuousServiceVertical.Activate
   intColumnCount_ContinuousService_Vertical = xlsSheetContinuousServiceVertical.UsedRange.Columns.Count
   strLastColumnName_ContinuousService_Vertical = Split(xlsSheetContinuousServiceVertical.Cells(1, intColumnCount_ContinuousService_Vertical).Address, "$")(1)
   xlsSheetContinuousServiceVertical.Columns("A:" & strLastColumnName_ContinuousService_Vertical).Delete (xlShiftToLeft)

   intColumnCount_ContinuousService_Vertical = xlsSheetContinuousServiceVertical.UsedRange.Columns.Count

   intColumnCount_ContinuousService_Vertical = xlsSheetContinuousServiceVertical.UsedRange.Columns.Count

   MsgBox intColumnCount_ContinuousService_Vertical

   MsgBox intColumnCount_ContinuousService_Vertical

//结束

每当我重新打开excel文件时,它运行良好,但是,如果我第二次运行Marco,我注意到了intColumnCount_ContinuousService_Vertical> 1. 

Everytime I reopen the excel file, It runs well, However, If I run the Marco second time , I noticed intColumnCount_ContinuousService_Vertical > 1. 

请指导我如何完全删除"UsedRange"表格中的区域?

Please guide how can I completly delete "UsedRange" Area in the sheet?

推荐答案

UsedRange将始终存在。如果您插入新工作表,则会使用范围"A1"

UsedRange will be always there. If you insert a new sheet, it will have usedrange "A1"


这篇关于请指导如何在Excel 2007中完全删除UsedRange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆