Use INDEX MATCH combo to INSERT value - VBA

raphads

New Member
Joined
Feb 17, 2023
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hello.

I have a code that uses the index match combo to set the cells value into the userForm, it works as expected.

Now I'm strugling trying to write a code that insert value into cells that are right next to the ones where the values came from.

here's the code I'm working

ps = txtPS.Value
inicioreal = txtInicioReal.Value


Range(Application.WorksheetFunction.Index(Sheets("Projetos").Range("K1:k1000"), Application.WorksheetFunction.Match(ps, Sheets("Projetos").Range("A1:A1000"), 0))).Value = inicioreal

When I run it gets the "Runtime error 1004 - unable to get match property of worksheetfunction class" message.


So, I want to get a value from a userform and write this value on a cell using index match, 'cause it's a table that is updated frequently so I cannot use a fixed range.
Can anyone help me with this or tell me another way of achieving this?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi and welcome to MrExcel.

According to your formula, I understand that you want to look in column A for the value that you have in txtPS and if it finds it, put the value txtInicioReal in column K.
If the above is correct, try like this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim ps As String, inicioreal As String
  Dim f As Range
  
  ps = txtPS.Value
  inicioreal = txtInicioReal.Value

  With Sheets("Projetos")
    Set f = .Range("A:A").Find(ps, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      .Range("K" & f.Row).Value = inicioreal
    Else
      MsgBox "Data ps does not exist"
    End If
  End With
End Sub
 
Upvote 1
Solution
Hi and welcome to MrExcel.

According to your formula, I understand that you want to look in column A for the value that you have in txtPS and if it finds it, put the value txtInicioReal in column K.
If the above is correct, try like this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim ps As String, inicioreal As String
  Dim f As Range
 
  ps = txtPS.Value
  inicioreal = txtInicioReal.Value

  With Sheets("Projetos")
    Set f = .Range("A:A").Find(ps, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      .Range("K" & f.Row).Value = inicioreal
    Else
      MsgBox "Data ps does not exist"
    End If
  End With
End Sub
It works PERFECTLY!

Thanks for the quick reply and thanks for the solution!
 
Upvote 1

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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