Excel循环VBA宏复制增量单元格范围到新工作表

时间:2017-09-29 03:35:07

标签: excel vba excel-vba

我正在尝试制作一个Excel VB宏,它将每列中的增量单元格逐渐复制到新的工作表中,然后将其导出为csv,以便在spss或jamovi中进行统计分析。

例如,如果我在A1:A50和B1:B50中有数据,我想复制A1:A(i)& B1:B(i)到工作表(i),i = i + 1,然后复制新范围A1:A(i)& B1:B(i)到新工作表。

这样的东西? (已从Excel loop VBA Macro copy cells to new sheetExporting Data into a CSV - Excel VBA修改)

Dim Static As Excel.Worksheet
Dim Temp As Excel.Worksheet
Dim i As Integer

Set Static = ActiveWorkbook.Worksheets("WIP_List") 

i = 1 'initial value of i 

'Copies incremental range to new sheets
Do While IsEmpty(Static.Range("A" & i).Value) = False 'loops through

Set Temp = ActiveWorkbook.Worksheets("set (" & i & ")")

Static.Range("A1" & : & "A" & i).Copy _
Destination:=Temp.Cell("A1")



'This part exports the worksheet as a csv

Set ws = ThisWorkbook.Worksheets(i)
 PathName = "" & ThisWorkbook.Path & "\" & ws.Name & ".csv"
ws.Copy
ActiveWorkbook.SaveAs Filename:=PathName, _
    FileFormat:=xlCSV, CreateBackup:=False

i = i + 1
Loop

我的想法是,如果我有N个样本,它将创建N个工作表,每个工作表的行数为i + 1。

0 个答案:

没有答案