我正在尝试创建一个VBA模块,该模块将从一个工作表中的表中获取数据并将其复制到第二个工作表中。然后,应将第二个工作表导出为PDF。
导出部分和为PDF命名不是问题,我仅在将数据从一张纸复制到另一张纸时解决。
该表的结构是,我有几行包含与我要在第二张纸上填写的发票相关的数据,我希望宏在整个文件中循环并仅获取所需的内容,但对于现在,我正在开发一个更简单的版本,我只想复制所选内容中的数据。
Option Explicit
Sub InvoiceCreator()
'create sheet
'Add info to sheet'
'save invoice sheet as PDF with name of customer
'reset sheet
'insert i+1 dataset
'loop til end
Dim sWS As Worksheet
Dim dWS As Worksheet
Dim sRange As Range
Dim sBNR As Range
Dim dBNR As Range
Dim sKNR As Range
Dim dKNR As Range
Dim sREF As Range
Dim dREF As Range
Dim sPRT As Range
Dim dPRT As Range
Dim sDAT As Range
Dim dDAT As Range
Dim sADR As Range
Dim dADR As Range
Dim sDES As String
Dim dDES As String
'Dim sPRC As Range
'Dim dPRC As Range
Dim i As Integer
Dim lastrow As Long
Set sWS = Sheets("Data")
Set dWS = Sheets("Sheet1")
Set sRange = Selection
Set sBNR = sRange.Cells(2, 7)
Set dBNR = dWS.Range("E4")
dBNR = sBNR.Value
Set sKNR = sRange.Cells(2, 2)
Set dKNR = dWS.Range("E6")
dKNR = sKNR.Value
Set sREF = sRange.Cells(2, 22)
Set dREF = dWS.Range("E8")
dREF = sREF.Value
Set sPRT = sRange.Cells(2, 23)
Set dPRT = dWS.Range("E10")
dPRT = sPRT.Value
Set sDAT = sRange.Cells(2, 4)
Set dDAT = dWS.Range("F4")
dDAT = sDAT.Value
lastrow = sRange.End(xlUp).Row
For i = 2 To lastrow
sDES = sRange.Cells(i, 12)
dDES = dWS.Range("A" & i + 23)
dDES = sDES
Next i
End Sub
大多数代码都能正常工作,并将值从一张纸复制到另一张纸,但是我被最后一个循环位卡住了。
我想获取一个单元格中字符串的值,并将其复制到另一张工作表中的一个单元格,然后复制下面的单元格的单元格值,并将其复制到下面一个单元格的另一个工作表中,直到我的结尾选择。我没有收到任何错误,但是它没有复制数据。
有什么建议吗?