Experts teach you how to use VBA code to quickly enter Excel data

  
When you enter data in a large number of Excel spreadsheets, pulling the scroll bar back and forth is both cumbersome and easy to go wrong, which is very inconvenient. So how do you quickly enter data in Excel? In fact, there are a lot of techniques for entering data in Excel, and using them reasonably can improve our work efficiency. This article takes a different approach and introduces you how to use VBA code to achieve fast data entry. Please see the example below.
Assume that in the column of data that is filled in, the department to which the employee belongs has "a workshop", "two workshops", "sales department", etc., if we can replace these text contents with numbers The words (pictured) will greatly improve the efficiency of our entry.
According to this idea, we entered the following code in the Change event of the worksheet:
Private Sub Workheet_Change(ByVal Target As Range)
If Target.Column = 2 Then ’Only in the second Columns implement this function
If Target.Value = 1 Then
Target.Value = "One Workshop"
Else
If Target.Value = 2 Then
Target.Value = " Second Workshop"
Else
If Target.Value = 3 Then
Target.Value = "Sales"
End If
End If
End If
End If
End Sub
returns to the Excel window, and the corresponding number can be replaced with the specified text content. Some friends may think that it is not OK to enter the data first and then use the search to replace it. However, we will find that it is easy to replace the data in other columns by the search and replace operation. If each number is confirmed and then replaced, it will be more cumbersome, and the code will not appear. After loading, It can be done once and for all.
Hint: In the code, "Target.Column = 2" is used to specify that it can only be valid when the data is entered in the second column (if it is not specified for the entire worksheet), so that you can enter these in other columns. The data will not be affected. Similarly, we can use code to control the fast entry of text in other columns. This technique is suitable for pre-loading into a form or programmed into a program for people who are not familiar with Excel, so that we can quickly fill out the form filled out by the employee (tick the corresponding numbered content or directly fill in the number of the specified content). Collect data.

Copyright © Windows knowledge All Rights Reserved