vba/macro to Find a line on another sheet and replace information in just 1 cell in that line

woodyp

New Member
Joined
Nov 26, 2024
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Hi

I am pretty new to Macro's/Vba etc and need a little help with the following if possible please.

I have a sheet where a user enters simple information to 'Book out' a specific piece of equipment that has a unique 'Item No."
when the user clicks the 'Book Out' button, all the information (shown just above the blue bar below) is copied and pasted as values into the correct position on this sheet. . . All this works good so far..

Before this happens though I would like to updated part of a record that already exists on another sheet with the 'Item No.' (A)

on the image below, A is the Item No. (which is a unique number on another sheet, but not neccesarily on this sheet).
and B is the infomation which will be copied. . . . again, no probs so far..

Image A.PNG


This is where I Need the help . . .
In the 'Equipment' sheet, i need search and find the unique Item No. (A) and replace the information in (B) with the information I have copied to the buffer... i.e. change the 'Missing' to 'Disposed'.

Image B.PNG


Is there a simple piece of coding that could help me with this??

Thanks in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If I understand your problem correctly, then this should help

VBA Code:
Sub find_Unique_Item(ItemText): i = 1
Do Until i > 1000
i = i + 1
If Cells(i, 2) = ItemText Then                     'Change 2 to whichever column the Unique Ids are in
    Cells(i, 8) = BufferText: GoTo earlyOut  'Change 8 to whichever column you want the output in
End If
Loop
earlyOut:
End Sub
 
Upvote 1
It is difficult to tell in which columns and rows your data is located. The macro assumes the following:
-the Item Number is in cell B6 and the Status is in cell H6
-the Item Numbers in the Equipment sheet are in column B
-the Status will be copied to column H in the Equipment sheet
Change the text in red to suit your needs.
Rich (BB code):
Sub CopyStatus()
    Dim desWS As Worksheet, item As Range
    Set desWS = Sheets("Equipment")
    Set item = desWS.Range("B:B").Find(Range("B6").Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not item Is Nothing Then
        desWS.Range("H" & item.Row) = Range("H6")
    End If
End Sub
The code should be placed in the macro that is executed when you click the Book Out button.
 
Upvote 0
Solution
Thank You *Cyb3r_Ang3l and mumps. . . I suppose I should have made it clearer by including the Columns and Row numbers eh :) ...

Anyway, I will try both solutions and see which one works best for me.

Thank you both again

 
Upvote 0
I tried mumps version first as my brain found it slightly easier to follow & understand what the code was doing :)

It worked perfectly so I have gone with that

Thanks again to you both
 
Upvote 0

Forum statistics

Threads
1,224,115
Messages
6,176,477
Members
452,728
Latest member
mihael546

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