Hello guys,
I just recently registered to the forum & thought you could help me out with a macro I am trying to build...
My VBA notion are very basic. I started a couple of weeks ago, so I am still trying to get my head around some stuff.
I am trying to replace some food codes in my survey with the corresponding description as per the USDA codes:
In column A ("Food code"), I have the food codes the survey participants consumed on that day (I have more than 1,000 different codes). The other columns are basically the "legend": in column B ("USDA code"), you can find the all available codes, whilst the corresponding description is found in column C ("Description").
What I want to do is to replace the food codes in column A ("Food Code") with the values in column C ("description"). So, theoretically, VBA should take cell A2 (94000100) & scan column B ("USDA codes") & then replace with the text in column C ("Description") once it finds 94000100 in column B.
Hope this makes sense.
I tried something super basic which is super wrong as I believe it only looks for direct matches:
Sub rplc()
Dim sh As Worksheet, lr As Long, rng As Range, c As Range
Set sh = Day1consumption
lr = sh.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh.Range("B2:B" & lr)
For Each c In rng
sh.Range("A:A").Replace What:=c.Value, Replacement:=c.Offset(0, 1).Value, LookAt:=xlPart, MatchCase:=False
Next
End Sub
Thank you very much for your help guys!
I just recently registered to the forum & thought you could help me out with a macro I am trying to build...
My VBA notion are very basic. I started a couple of weeks ago, so I am still trying to get my head around some stuff.
I am trying to replace some food codes in my survey with the corresponding description as per the USDA codes:
In column A ("Food code"), I have the food codes the survey participants consumed on that day (I have more than 1,000 different codes). The other columns are basically the "legend": in column B ("USDA code"), you can find the all available codes, whilst the corresponding description is found in column C ("Description").
What I want to do is to replace the food codes in column A ("Food Code") with the values in column C ("description"). So, theoretically, VBA should take cell A2 (94000100) & scan column B ("USDA codes") & then replace with the text in column C ("Description") once it finds 94000100 in column B.
Hope this makes sense.
I tried something super basic which is super wrong as I believe it only looks for direct matches:
Sub rplc()
Dim sh As Worksheet, lr As Long, rng As Range, c As Range
Set sh = Day1consumption
lr = sh.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh.Range("B2:B" & lr)
For Each c In rng
sh.Range("A:A").Replace What:=c.Value, Replacement:=c.Offset(0, 1).Value, LookAt:=xlPart, MatchCase:=False
Next
End Sub
Thank you very much for your help guys!