[VBA] Compare cell content from sheet to sheet and display offset in Msgbox

Eawyne

New Member
Joined
Jun 28, 2021
Messages
22
Office Version
  1. 2013
Platform
  1. Windows
Hi all =)

my needs could be summarized this way : when I write an ID in a cell from Row 2 in Sheet1, it should check the content of Row1 from Sheet2 => if there is a match (ie. A3), then the content of the adjacent matching cell (B3) from Sheet2 should be displayed in a Msgbox.

This can be linked to this thread ; the main problem is the same : I'm able to identify some solutions but none answers the precise options I'd want (display a result in the msgbox, for example) and I can't find a way to merge the various bits of code :confused:

I've looked up several queries, going on threads like this or even this here, but I truly do lack the bascis to tie it all together, which is frustrating as I technically have the start from my previous thread !

Any help is welcome :)
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Eawyne

New Member
Joined
Jun 28, 2021
Messages
22
Office Version
  1. 2013
Platform
  1. Windows
I found this code :

VBA Code:
Sub mesage()
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xStr As String
    Dim xRow As Long
    Dim xCol As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("Please select range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    On Error Resume Next
    For xRow = 1 To xRg.Rows.Count
        For xCol = 1 To xRg.Columns.Count
            xStr = xStr & xRg.Cells(xRow, xCol).Value & vbTab
        Next
        xStr = xStr & vbCrLf
    Next
    MsgBox xStr, vbInformation, "Kutools for Excel"
End Sub

which kinda has some of the variables I could need. I managed to make the relation with the xStr being the value I'd want to see displayed, at the very least...
 

Forum statistics

Threads
1,143,692
Messages
5,720,313
Members
422,276
Latest member
streasure

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
Top