VBA to search for value and return date from another cell

hgc2016

New Member
Joined
Dec 7, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have copied this VBA from a site and tried to change to suit my requirements. It was to search for the word "HZI" in a column (column BO), if a match then it returns the date from another cell on the same row (column BL). It works if there is HZI in any part of the cell, I only need it to only return the date when the cell starts with HZI, please help!

VBA Code:
Sub FindPARTMENT()
    Dim ws As Worksheet
    Dim match As Range
    Dim findMe As String
    Dim findOffset As String
    Dim sAdr  As String
   
    Application.ScreenUpdating = False
   
    Set ws = ThisWorkbook.ActiveSheet
    findMe = "HZI"
   
    Set match = ws.Range("BO:BO").Find(findMe)
    If Not match Is Nothing Then
        sAdr = match.Address
        Do
            match.Offset(0, 18).Value = match.Offset(0, -3).Value
            Set match = ws.Range("BO:BO").FindNext(match)
        Loop Until match Is Nothing Or match.Address = sAdr
    End If

   
End Sub
 
Last edited by a moderator:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub hgc()
   With Range("BO2", Range("BO" & Rows.Count).End(xlUp))
      .Offset(, 18).Value = Evaluate(Replace("if(left(" & .Address & ",3)=""HZI""," & .Offset(, -3).Address & ",if(@<>"""",@,""""))", "@", .Offset(, 18).Address))
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,449
Messages
6,124,911
Members
449,195
Latest member
Stevenciu

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