Problem Execute button another sheet

NerakSeven

New Member
Joined
Jan 6, 2019
Messages
14
I create a button in sheet1 and this is works only in this sheet not in sheet46. The problem is I need this button in another page(sheet46) I mean call this action from another sheet46 with the same reference (check sheet 1 and sheet2)
Why don’t works?

Code:

Private Sub CommandButton1_Click()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lr1 As Long
Dim lr2 As Long
Set ws1 = Sheet(“Sheet1”)
Set ws2 = Sheet(“Sheet2”)
lr1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
lr2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To lr2
If Cells(x, "B") <> Application.WorksheetFunction.SumIfs(ws1.Range("I2:I" & lr1), ws1.Range("A2:A" & lr1), Cells(x, "A")) Then
ws2.Cells(x, "I") = "Not correct"
End If
Next x



End Sub



I hope u can help me ,

Regards
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
It would help us to help you if you gave us something more than "Why don’t works?".
Like do you get any error messages, if so what & where?

That said try these changes
Code:
Set ws1 = Sheet[COLOR=#ff0000]s[/COLOR]([COLOR=#ff0000]"[/COLOR]Sheet1[COLOR=#ff0000]"[/COLOR])
Set ws2 = Sheet[COLOR=#ff0000]s[/COLOR]([COLOR=#ff0000]"[/COLOR]Sheet2[COLOR=#ff0000]"[/COLOR])
 
Upvote 0
Which sheet(s) are Cells meant to reference here?
Code:
If Cells(x, "B") <> Application.WorksheetFunction.SumIfs(ws1.Range("I2:I" & lr1), ws1.Range("A2:A" & lr1), Cells(x, "A")) Then
 
Upvote 0
Is the code you supplied in your OP the code for button "M"?
 
Upvote 0
thanks !! now works

Code:

Code:
 If ws2.Cells(x, "B") <> Application.WorksheetFunction.SumIfs(ws1.Range("B2:B" & lr1), ws1.Range("A2:A" & lr1), ws2.Cells(x, "A")) Then
        ws2.Cells(x, "D") = "Not correct"


Which sheet(s) are Cells meant to reference here?
Code:
If Cells(x, "B") <> Application.WorksheetFunction.SumIfs(ws1.Range("I2:I" & lr1), ws1.Range("A2:A" & lr1), Cells(x, "A")) Then
 
Upvote 0

Forum statistics

Threads
1,224,943
Messages
6,181,921
Members
453,071
Latest member
Gizmo2024

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