Application.WorksheetFunction.Match

mulholm

New Member
Joined
Jul 2, 2018
Messages
49
Option Explicit


Sub TeamTotal()
Dim lngRow As Long

With Sheet1
'find "Team Total" position
lngRow = Application.WorksheetFunction.Match("Team Total", .Range("A:A"), 0)
'apply the sum formula
.Range("B" & lngRow).Formula = "=SUM(B1:B" & lngRow - 1 & ")"
End With


End Sub



is there any way to change this so that it runs the search on sheet2 but command button is on sheet1?

I have tried simply changing "With sheet1" to "With sheet2" but no joy.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Are you saying it makes no difference if you change With Sheet1 to With Sheet2?? It does. But it will then place your formula on Sheet2 also. So instead of just using the period you can say Sheet2.Range("A:A")
 
Upvote 0
Private Sub TeamTotal()

Dim lngRow As Long

With Sheet2

'find "Team Total" position
lngRow = Application.WorksheetFunction.Match("Team Total", .Range("A:A"), 0)

'apply the sum formula
.Range("B" & lngRow).Formula = "=SUM(B3:B" & lngRow - 1 & ")"
.Range("C" & lngRow).Formula = "=SUM(C3:C" & lngRow - 1 & ")"
.Range("E" & lngRow).Formula = "=SUM(E3:E" & lngRow - 1 & ")"

End With


End Sub



I have changed it to the above code and it debugs highlighting the bolded section.

i want the formula to only appear in sheet 2 instead of sheet 1 but the button to trigger the formula is on sheet 1
 
Last edited:
Upvote 0
And the error is? 'Unable to get.....'? If so then Team Total is not found in column A of Sheet2.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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