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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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