Worksheet Formula as VBA Code

dbnfl

Board Regular
Joined
Aug 11, 2019
Messages
59
Hello,

I'm trying to convert a work sheet formula to VBA.

I enter a new job in a user form, when I hit continue and info transfers to "Data" sheet I want code to run and update.

Sub Vessel_Details_WorksheetChange()

'my formula on worksheet =INDEX('Wharf Schedules'!B:B,MATCH(Data!AO59&Data!AQ59,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0))


With Range("AL5:AL" & Range("AO" And "AQ" & Rows.Count).End(xlUp).Row)
.Formula = "=IFERROR(INDEX('Worksheet3'!B:B,MATCH('Worksheet'!"AO" And "AQ",'Worksheet2'!C:C&'Worksheet2'!E:E,0)),"""")"
.Value = .Value
End With
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this

Code:
With Range("AL5:AL" & Cells(Rows.Count, "AL").End(xlUp).Row)
   .Formula = "=IFERROR(INDEX('Wharf Schedules'!C2,MATCH('Data'!RC41&RC43,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0)),"""")"
   .Value = .Value
End With
 
Upvote 0
Maybe
Code:
Range("AL5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!C:C,MATCH('Data'!AO5&AQ5,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)
   .FillDown
   .Value = .Value
End With
 
Upvote 0
Hello,

Didn't have any luck with code suggestions.

I wan this code to run on worksheet change. I have the code in worksheet1("Data") view code.
 
Upvote 0
If neither of the codes worked, why did you Start a new thread, using one of them?
 
Upvote 0
Hello Fluff,

I tried to post about adding in more code to same sub. I thought I posted about that and tried finding post but couldn't fi it. That's why the 2nd post.

I got your ode to work.

What I need to do now is add o code o more columns au fill.

Code I have is below with your help, and thank you for that

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'my formula on worksheet =INDEX('Wharf Schedules'!B:B,MATCH(Data!AR59&Data!AT59,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0))

Range("AL5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!B:B,MATCH('Data'!AR5&AT5,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)
.FillDown
.Value = .Value
End With

End Sub

I'm not sue how to add more code to it Eg.

Range("AP5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!G:G,MATCH('Data'!AR5&AT5,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)

Range("AQ5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!I:I,MATCH('Data'!AR5&AT5,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)

Range("AS5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!D:D,MATCH('Data'!AR5&AR5,'Wharf Schedules'!C:C&'Wharf Schedules'!E:E,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)

Range("AU5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!Q:Q,MATCH('Data'!AR5&AR5,'Wharf Schedules'!M:M&'Wharf Schedules'!O:O,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)

Range("AW5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!R:R,MATCH('Data'!AR5&AR5,'Wharf Schedules'!M:M&'Wharf Schedules'!O:O,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)

Range("AV5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!S:S,MATCH('Data'!AR5&AR5,'Wharf Schedules'!M:M&'Wharf Schedules'!O:O,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)

Range("AW5").FormulaArray = "=IFERROR(INDEX('Wharf Schedules'!T:T,MATCH('Data'!AR5&AR5,'Wharf Schedules'!M:M&'Wharf Schedules'!O:O,0)),"""")"
With Range("AL5:AL" & Cells(Rows.Count, "B").End(xlUp).Row)

Dale
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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