Home > Software engineering >  Vb traversal excel column batch to create a sheet
Vb traversal excel column batch to create a sheet

Time:11-08

Have A excel file test. XLSX, sheet1 inside A column value A1 to A3=(" AAA ", "BBB", "CCC"), to read these three values, cycle to create three sheet in the value of name, and then the inside of the respective sheet A1 value equal to the value, have A great god?

CodePudding user response:

 Sub (new) 
Dim the ws As Worksheet
Dim i& , s $s1 $
S1="table already exists"
With ThisWorkbook. Sheets (" Sheet1 ")
For I=1 To.. Cells (Rows) Count, 1.) the End (xlUp). Row
S=. Cells (I, 1)
On the Error Resume Next
With ThisWorkbook. Sheets (s)
If Err. Number Then
With ThisWorkbook. Sheets. The Add (after:=ThisWorkbook. Sheets (ThisWorkbook. Sheets. Count))
.name=s
Cells (1, 1)=s
Err. Clear
End With
The Else
S1=s & amp; CRH (13) & amp; S1
End the If
End With
Next
End With
If s1 & lt;> "Table already exists" Then MsgBox s1
End Sub

CodePudding user response:

Private Sub CommandButton1_Click ()
As Integer Dim a, b As String
B="Sheet1"
For a=1 To 3
Worksheets. Add after:=Worksheets (b)
ActiveSheet. Name=Worksheets (" Sheet1 "). The Range (" A "& amp; A)
ActiveSheet. Range (" A1 ")=Worksheets (" Sheet1 "). The Range (" A "& amp; A)
B=Worksheets (" Sheet1 "). The Range (" A "& amp; A)
Next a
End Sub
  •  Tags:  
  • VBA
  • Related