VBA CODE HELP

dlafko1

New Member
Joined
Oct 22, 2017
Messages
18
Hello,
I have this code (which someone provided)
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  1/3/2020  8:58:13 AM  EST
If Target.Column = 2 Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim ans As Variant
ans = Target.Value
Dim dteRow As Variant
Dim x As Variant
With Sheets("JobCode_Name")
    dteRow = Application.Match(ans, .Columns(1), 0)
    
      If IsNumeric(dteRow) Then
            x = .Cells(dteRow, 2).Value
            Target.Offset(, 1).Value = x
    Else
        MsgBox ans & vbNewLine & "Notfound"
    End If
End With
End If
End Sub

It takes a number in Columb 2 of my sheet and then puts in other data in Columb 3 I have the data on a separate sheet.

I would like to do the same thing in another columb.
I want to in Columb 6 add text which then puts a number in Columb 5 the data is stored on another sheet called Agency Code.

I tried this but it did not work

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  1/3/2020  8:58:13 AM  EST
If Target.Column = 6 Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim ans As Variant
ans = Target.Value
Dim dteRow As Variant
Dim x As Variant
With Sheets("AgencyCode_Name")
    dteRow = Application.Match(ans, .Columns(5), 0)
    
      If IsNumeric(dteRow) Then
            x = .Cells(dteRow, 2).Value
            Target.Offset(, 1).Value = x
    Else
        MsgBox ans & vbNewLine & "Notfound"
    End If
End With
End If
End Sub

Any Guideance would be great. I am not good with VBA and this was the first time I put code in an excel sheet. The data is stored on the sheet called Internal.

Thanks for the help.
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

n1lesh

Board Regular
Joined
Apr 3, 2015
Messages
61
If the sheet is called Internal change
With Sheets("AgencyCode_Name") to
With Sheets("Internal")
 

dlafko1

New Member
Joined
Oct 22, 2017
Messages
18
If the sheet is called Internal change
With Sheets("AgencyCode_Name") to
With Sheets("Internal")

Sorry the Sheet that has the Data I want to choose is from AgencyCode
The sheet the data will be put in to is internal.

So the code I was trying to change takes information from a sheet call JobCodes and then stores it in the Internal Sheet.. I want to do the same thing with another set of data in different columns
 

Watch MrExcel Video

Forum statistics

Threads
1,122,352
Messages
5,595,657
Members
414,006
Latest member
Davefromlondon

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
Top