VBA IF Function Help

Bolsa68

New Member
Joined
Apr 13, 2016
Messages
4
Hello,

What would be the proper way to write the following in VBA language?

if Window1,Sheet1,Range A1 = Window2,Sheet2,Range A2 then
exit sub
end if

What I am trying to do is a macro that if a cell in a workbook is the same as another cell in a different workbook, the code will exit. The cells that I am comparing are a time stamp that looks like this: 13-Apr-2016 10:00:09 AM AST
Any help would be greatly appreciated!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hello,

What would be the proper way to write the following in VBA language?

if Window1,Sheet1,Range A1 = Window2,Sheet2,Range A2 then
exit sub
end if

What I am trying to do is a macro that if a cell in a workbook is the same as another cell in a different workbook, the code will exit. The cells that I am comparing are a time stamp that looks like this: 13-Apr-2016 10:00:09 AM AST
Any help would be greatly appreciated!
Hi Bolsa68, welcome to the boards.

It should be something simple along these lines. Be sure to amend the bold red part with the correct name of the second workbook:

Rich (BB code):
Sub Check()
' Defines variables
Dim wb1 As Workbook, wb2 As Workbook


' Defines which workbook is which
Set wb1 = ThisWorkbook
Set wb2 = "The Other Workbook Name.xlsx"


' If the value of Sheet1 A1 of workbook 1 matches Sheet2 A2 of workbook 2 then...
If wb1.Sheets("Sheet1").Range("A1").Value = wb2.Sheets("Sheet2").Range("A2").Value Then
    ' Exit the macro
    Exit Sub
End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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