Update Data Automatically

Ivy_1011

New Member
Joined
Mar 19, 2021
Messages
18
Platform
  1. Windows
I have an excel worksheet that when I run the code, it enters the cell data based on the number I place in Column 1 or item column. In order to retrieve the data, I have to run the code using a macro-assigned button.

My objective is to have the data populated in Columns 2 and 3 automatically upon entering the item number in column 1. Below is the code and tables per Tab name. I tried uploading the workbook but I do not see that option anymore.

Sub Input_Data()

Dim i As Integer

On Error Resume Next

For i = 2 To 30
Worksheets("Test").Cells(i, 2) = Application.WorksheetFunction.VLookup(Worksheets("Test").Cells(i, 1), Worksheets("Imports").Range("A2:C30"), 2)
Worksheets("Test").Cells(i, 3) = Application.WorksheetFunction.VLookup(Worksheets("Test").Cells(i, 1), Worksheets("Imports").Range("A2:C30"), 3)
Next i


End Sub

"Test" Tab

ItemDescriptionColor
1peachcoral
1peachcoral
2applered
1peachcoral
5kiwigreen
1peachcoral
1peachcoral


"Imports" Tab

1​
peachcoral
2​
applered
3​
orangeorange
4​
kiwigreen
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Go to the Test sheet, and right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this code in the VB Editor window that pops-up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if multiple cells updated at once
    If Target.CountLarge > 1 Then Exit Sub
   
'   See if update made to column 1 below row 1
    If Target.Column = 1 And Target.Row > 1 Then
'       Populate formulas in columns B and C
        Application.EnableEvents = False
        Target.Offset(0, 1).Value = Application.WorksheetFunction.VLookup(Target.Value, Worksheets("Imports").Range("A2:C30"), 2)
        Target.Offset(0, 2).Value = Application.WorksheetFunction.VLookup(Target.Value, Worksheets("Imports").Range("A2:C30"), 3)
        Application.EnableEvents = True
    End If
   
End Sub
This should automatically update columns B and C whenever you manually type an entry into column A on that sheet.
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top