简体   繁体   English

excel vba 编码用于数据输入

[英]excel vba coding for data entry

Im new in coding.我是编码新手。 I have an Excel file with 2 sheets.我有一个带有 2 张纸的 Excel 文件。 Sheet1 is data entry, and sheet2 database. Sheet1是数据输入,而sheet2是数据库。 In sheet1 I have 4 variables: Id , Name , Old , Email .sheet1我有 4 个变量: IdNameOldEmail And I want to use ActiveX control (command button).我想使用 ActiveX 控件(命令按钮)。

I want when I fill the data in sheet1 and press the button it should copy the data to the sheet2 (image below showing sheet2 ), also if I want to fill another data it should go down 2 rows for new data (as row 9 in image).我想当我在sheet1中填充数据并按下按钮时,它应该将数据复制到sheet2 (下图显示sheet2 ),如果我想填充另一个数据,它应该 go 向下 2 行以获取新数据(如第 9 行图片)。 Thanks for helping.感谢您的帮助。

在此处输入图像描述

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    
    Dim iRow As Long  
    iRow = Sheets(2).Range("A1048576").End(xlUp).Row + 1
     
    With ThisWorkbook.Sheets(2)
       .Range("A" & iRow).Value = Sheet1.Range("A5").Value
       .Range("A" & iRow + 1).Value = Sheet1.Range("A6").Value
       .Range("B" & iRow).Value = Sheet1.Range("B5").Value
       .Range("B" & iRow + 1).Value = Sheet1.Range("B6").Value
       .Range("C" & iRow).Value = Sheet1.Range("C5").Value
       .Range("C" & iRow + 1).Value = Sheet1.Range("C6").Value
       .Range("D" & iRow).Value = Sheet1.Range("D5").Value
       .Range("D" & iRow + 1).Value = Sheet1.Range("D5").Value          
    End With

    Call Reset
    Application.ScreenUpdating = True
End Sub
Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    
    Dim iRow As Long  
    iRow = Sheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1 
    If iRow <> 5 Then iRow = iRow + 2  'add two rows if not first dataset

    '...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM