从包含空格的列表中创建并命名新工作表

时间:2015-11-02 17:59:04

标签: excel vba excel-vba

我需要帮助编写一个宏,它将根据命名范围(ARK_E_TEXAS_LIST)创建一个新工作表。新工作表名称将来自命名范围中的列A,但是,该列将包含空白,但列C将包含所有行中的数据。不幸的是,这就是我需要列表的方式。

是否可以创建新工作表并从A列命名并传递空白?

        A       B           C    
   1    AR0000RK            BLDG CPLX 1
   2            AR0030RK    SUB BLDG 1
   3            AR0063RK    SUB BLDG 2
   4            AR0082RK    SUB BLDG 3
   5            AR0085RK    SUB BLDG 4
   6            07020850    SUB BLDG 5
   7    TX0000TY            BLDG CPLX 2 
   8            TX0182TY    SUB BLDG 1
   9            TX0262TY    SUB BLDG 2  
   10           07020830    SUB BLDG 3
   11   AR0021ZZ            BLDG 1  
   12   AR0031ZZ            BLDG 2
   13   AR0057ZZ            BLDG 3
   14   AR0062ZZ            BLDG 4
   15   AR0066ZZ            BLDG 5
   16   AR0078ZZ            BLDG 6    
   17   AR0079ZZ            BLDG 7
   18   AR0084ZZ            BLDG 8
   19   TX0019ZZ            BLDG 9
   20   TX0126ZZ            BLDG 10
   21   TX0130ZZ            BLDG 11
   22   TX0210ZZ            BLDG 12
   23   TX0404ZZ            BLDG 13
Sub Create_ARK_E_TEXAS()
Dim sht As Worksheet
Dim newSheetName As Range
Dim dataRange As Range
Dim Lastrow As Long

Set sht = ThisWorkbook.Sheets("ARK_E_TEXAS")
Set newSheetName = sht.Range("A1:A")
Lastrow = sht.Range("ARK_E_TEXAS_LIST").Rows.Count
Set dataRange = sht.Range("A1:C" & Lastrow)

For Each newSheetName In dataRange
**If newSheetName > 0 Then
    Sheets.Add After:=Sheets(Sheets.Count) 'creates a new worksheet
    Sheets(Sheets.Count).Name = newSheetName.Value ' renames the new worksheet
    Else: End If**
    Sheets.Add After:=Sheets(Sheets.Count) 'creates a new worksheet
    Sheets(Sheets.Count).Name = newSheetName.Value ' renames the new worksheet
Next newSheetName
End Sub

1 个答案:

答案 0 :(得分:-1)

#include "hdrSamePath.h"
#include "hdrMainFolder.h"
#include "hdrDifferentPath.h"