'Using VBA to loop through a column for a value then copy contents of row to another sheet
I'm trying to do something I think is simple In Excel with VBA. I want to loop through a column searching for a certain value and when I find it, copy some of the data out of that row into another worksheet. I found this answer doing something similar, loop through column. But I'm having trouble adapting it. When I search the value I get the name of the person I'm trying to search for copied into the other worksheet, and it copies it the same amount of times I have in the range. So when I update the range it just copies it the same amount of times. Currently, I'm just trying to loop through the column and find the name, then ultimately use that as a locator to isolate the row and copy some data out of it. The name I'm looking for is in some kind of list box in the worksheet. I thought for a while it was a list box and then I thought it was a combo box because when I select the cell it has a drop-down to select several names from. But when it's a list box or some other entity it will tell you its name in the name box on the ribbon, and when I select the cell it just has the cell's address in it. So I should just be able to use the value of the cell to search the column? I'm sure I'm missing something basic. Anyways here is the code I came up with.
Public Sub copyValuesFromWeek()
Dim c As Range
Dim techName As String
Dim techNameFound As Range
techName = InputBox("What is your name?", "Tech Worksheet")
Set c = Sheets("03-7-2022 TECH SCHEDULING").Range("AL21:AL5000")
Set techNameFound = c.Find(techName, , xlValues, xlWhole)
If Not techNameFound Is Nothing Then
Sheets("Tech Week").Range("B3:B40").Value = techName
End If
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
