If Cell<Another Cell

atclaeys

New Member
Joined
Sep 20, 2011
Messages
7
I'm attempting to write a VBA macro to check if the last cell in a column is less than another cell*0.85 to display a message box with a warning. I would then like to select the cell two columns over and compare to another cell if the first value is ok.

Code:
Worksheets("Plots").Activate
Worksheets("Plots").Range("B1").Select
Selection.End(xlDown).Select
If Selection.Value <= (610 * 0.85) Then
    MsgBox "message1"
    ElseIf ActiveCell.Offset(0, 2).Value <= (Worksheets("Main").Range("F17").Value * 0.85) Then
    MsgBox "message2"
End If

This is part of a larger macro (which works without these lines of code) that I am wanting to link to a single button (thus no sub). The code works fine when I put in the actual numerical value of the cell, but I would like to be able to manipulate this value before running the macro from the worksheet. The two cells to compare values against are F12 and F17 for messages 1 and 2, respectively, and are on worksheet named 'Main'.

Thanks for your time and any help! Happy to clarify/answer questions if something is unclear.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Something like this maybe?

Code:
With Sheets("Plots")
    If .Range("B1").End(xlDown) <= Sheets("Main").Range("F12") * 0.85 Then
        MsgBox "Message1"
    ElseIf .Range("B1").End(xlDown).Offset(, 2) <= Sheets("Main").Range("F17") * 0.85 Then
        MsgBox "Message2"
    End If
End With
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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