image 2Sometimes we want to use one sheet of the excel as a form that is used to get the inputs from the user. the data entered by the user, we try to save it on some other sheets that may notbe accessible to the end user for the security of the data of course. In this article, we will learn how to how we can update data from one sheet to another using VBA.

因此,在不进一步讨论我无聊的话题的情况下,让我们深入研究一个例子来理解这个概念。

示例:基于在Sheet1上输入的值更新Sheet2上的数据我们要为在呼叫中心工作的那些雇员编写此代码。客户呼叫他们时,他们会使用基本详细信息,例如User_Name,User_ID,Phone_Number和Problem_ID。

现在,我们要编写宏,以便当有电话呼叫时,他们会将上述所有详细信息记录到excel工作表中,而当他们单击update时,应该在另一工作表中更新数据。

image 1

要将数据从一张纸更新到另一张纸,请执行以下步骤:-•首先,我们将在工作表中插入命令按钮。

•转到“开发人员”选项卡,然后从Activexcontrol插入“命令”按钮。

•分配以下宏:-

Private Sub CommandButton1_Click()

Dim User_Name As String, User_ID As Integer, Phone_Number As Double, Problem_ID As Integer

Worksheets("Sheet1").Select

User_Name = Range("B2")

User_ID = Range("B3")

Phone_Number = Range("B4")

Problem_ID = Range("B5")

Worksheets("Sheet2").Select

Worksheets("Sheet2").Range("A1").Select

If Worksheets("Sheet2").Range("A1").Offset(1, 0) <> "" Then

Worksheets("Sheet2").Range("A1").End(xlDown).Select

End If

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = User_Name

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = User_ID

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = Phone_Number

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = Problem_ID

Worksheets("Sheet1").Select

Worksheets("Sheet1").Range("B2").Select

End Sub

代码说明:-首先,我们定义了所有变量。然后我们定义了每个变量的范围,然后描述了所有变量的范围。我们已经定义了单击“更新”按钮后数据将在何处以及在哪个范围内更新。

image 2

•要运行代码,请按键盘上的F5键。

•当您输入数据并单击更新按钮时,数据将在另一个工作表中更新,我们可以在工作表中输入新数据。

image 3

image 4

这样,我们可以通过Microsoft excel中的VBA将数据从一张表更新到另一张表。我希望我能解释得足够。如果您对本文或任何其他excel VBA文章有任何疑问,可以在下面的评论部分中问我。

image 48

相关文章

`link:/ applications-word-outlook-in-vba-getting-started-excel-vba-userforms [Excel VBA UserForms入门] || * Excel UserForms对于从用户获取信息很有用。这是从VBA用户格式开始的方法

===

更改多个用户窗体控件的值/内容在Excel中使用VBA] || *要更改用户窗体控件的内容,请使用此简单的VBA代码段。

当用户单击在Microsoft Excel中使用vba的x按钮时,`link:/ user-forms-input-boxes在vba中防止关闭的用户窗体[通过在Excel中使用VBA防止用户单击x按钮时关闭用户窗体。为了防止用户单击表单的x按钮时关闭用户窗体,我们使用UserForm_QueryClose事件。

热门文章:

`link:/ keyboard-formula-shortcuts-50-excel-shortcuts可提高您的生产率[50 Excel快捷方式可提高生产率]] |更快地完成任务。这50个快捷键将使您在Excel上的工作速度更快。

link:/ vlookup-functions的公式和函数介绍[Excel中的VLOOKUP函数]|这是excel中最常用和最受欢迎的功能之一,用于从不同范围和工作表中查找值。

link:/ tips-countif-in-microsoft-excel [Excel 2016中的COUNTIF]|使用此惊人的功能对条件进行计数。您无需过滤数据即可计算特定值。

Countif功能对于准备仪表板至关重要。

link:/ excel-formula-and-function-excel-sumif-function [如何在Excel中使用SUMIF函数]|这是仪表板的另一个重要功能。这可以帮助您汇总特定条件下的值。