如何使用宏按钮将数据表中的数据添加到另一个表中?

时间:2022-05-14 20:10:02

I want to add data with a button from a data sheet to a bill sheet, but its not working. The code is working correctly when I'm running at bill sheet but doesn't work when I run it in the data sheet.

我想用一个按钮从数据表添加数据到账单表,但是它不起作用。当我在bill表上运行时,代码正常工作,但是当我在数据表中运行时,代码就不正常了。

Here is my code:

这是我的代码:

Sub Button1_Click()
Dim i As Integer

For i = 22 To 42
If IsEmpty(Range("C" & i)) Then

Sheets("PRICE LIST").Range("C3").Copy Destination:=Sheets("INVOICE EU").Range("C" & i)
Sheets("PRICE LIST").Range("D3").Copy Destination:=Sheets("INVOICE EU").Range("E" & i)
Sheets("PRICE LIST").Range("E3").Copy Destination:=Sheets("INVOICE EU").Range("K" & i)
Sheets("INVOICE EU").Range("L" & i).Value = Sheets("PRICE LIST").Range("F3").Value

Exit For

Else
End If
Next i

End Sub

data sheet is PRICE LIST and bill sheet is INVOICE EU

数据表为价格表,账单表为EU发票

1 个解决方案

#1


1  

You mention that the macro has different effects on different sheets. The line defined below is dependent on the sheet with focus

您提到宏对不同的表有不同的影响。下面定义的线依赖于有焦点的页面

If IsEmpty(Range("C" & i)) Then

Is it possible you want to refer to a particular sheet when checking range c22:c42?

在检查范围c22:c42时,是否可以参考特定的表?

#1


1  

You mention that the macro has different effects on different sheets. The line defined below is dependent on the sheet with focus

您提到宏对不同的表有不同的影响。下面定义的线依赖于有焦点的页面

If IsEmpty(Range("C" & i)) Then

Is it possible you want to refer to a particular sheet when checking range c22:c42?

在检查范围c22:c42时,是否可以参考特定的表?