VBA intersect row and column code

jaym6939

New Member
Joined
Jun 26, 2020
Messages
43
Office Version
  1. 365
Platform
  1. Windows
i am writing code to update spreadsheet cell value with intersect function. i have below code that search UserForm3.txtchangenumber in range I1 to AZA1 (worksheet "Cost") and search userform1.txtselectedpart in range E4 to E250(worksheet "Cost"). i would like to populate cell in (worksheet "Cost") when both search intersect by using intersect function.
below is code what i have right now. but it gives me run time erroe 1004 method range of object _global failed.
can you pl help me to understand what is error by correcting below code.

VBA Code:
Private Sub txtdelta_AfterUpdate()

Dim vrech As Range
Dim lColumn As Range
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Cost")


'Dim colonne As Long
        'colonne = Me.ComboBox1.Value
Set lColumn = sh.Range("i2:AZa2").Find(UserForm3.txtchangenumber, , xlValues, xlWhole) 'LookIn:=xlValues)
Set vrech = sh.Range("E4:E250").Find(UserForm1.txtselectedpart, , xlValues, xlWhole) 'LookIn:=xlValues)


     Intersect(Range("vrech"), Range("col")) = UserForm1.txtdelta.Value
 


End Sub
 
Jasonb75,
thanks a lot for your help on this. i have found error in code and file. by mistake very 1st column was hidden in out put and i have reference to look up value in column 2 instead of 1. below codes works.
VBA Code:
Private Sub txtdelta_AfterUpdate()

Dim vrech As Range
Dim lColumn As Range
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Cost")

Set lColumn = sh.Range("i1:AZa1").Find(UserForm1.txtdummy.Value, , xlValues, xlWhole)

Set vrech = sh.Range("E4:E250").Find(UserForm1.txtselectedpart.Value, , xlValues, xlWhole)
If vrech Is Nothing Then
    MsgBox "Row not found"
ElseIf lColumn Is Nothing Then
    MsgBox "Column not found"
Else
    Intersect(vrech.EntireRow, lColumn.EntireColumn) = UserForm1.txtdelta.Value
End If
End Sub

once again thanks for your support and time.(y)?
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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