PDA

View Full Version : VBA to check column I and if find data and match the same ID in column A Put Data in.



parscon
12-11-2018, 03:26 AM
Hi everyone
I need your help .
I need VBA to check column I and if find data and match the same ID in column A Put Data on Column D (If column D is Empty)

For Example :

23389

Please help me if you can .

Thanks for your time and effort.

Kenneth Hobs
12-11-2018, 07:01 PM
Sub Main()
Dim aR As Range, a, i As Long, j As Long, v

Set aR = Range("A1", Cells(Rows.Count, "A").End(xlUp))
ReDim a(1 To aR.Cells.Count)

For i = 1 To UBound(a)
For j = 1 To UBound(a)
v = Cells(j, "I").Value
If v = "" Then GoTo NextJ
If Cells(i, "A").Value = Cells(j, "A").Value Then _
a(i) = v
NextJ:
Next j
Next i

Range("D1").Resize(UBound(a)).Value = WorksheetFunction.Transpose(a)
End Sub

parscon
12-11-2018, 10:29 PM
Really you are you are awesome . Good Job Man .

parscon
01-02-2019, 08:47 AM
Dear Kenneth Hobs
Just there is one problem , if D Column has a data it must not replace by the data on I Column .

Could you please fix that ?

Kenneth Hobs
01-02-2019, 09:06 AM
I am not sure why that would matter. Maybe:

'Range("D1").Resize(UBound(a)).Value = WorksheetFunction.Transpose(a)
For i = 1 To UBound(a)
Set aR = Cells(i, "D")
If aR = "" Then aR = a(i)
Next i