Avatar of jnikodym
jnikodym
 asked on

Excel VBA - I'm looking for code that will loop through a column and return a value to another column if a condition is true.

I have data in Column H of my excel file.  I want to hit a button on the sheet that will loop through the data in column H and if the data is not blank or a zero i want the value that is in that cell to be placed in cell J1.  Then if it finds another value that is not blank or a zero i want that value place in cell J2 and so on.

If my H column looked like this:
H1 = Green
H2 =
H3 = 0
H4 = 0
H5 = Blue

I would want my J column to look like this:
J1= Green
J2= Blue
Microsoft ExcelVBA

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
Professor J

Sub test

With activesheet
LR= .cells(.cells.rows.count, "H").end(xlup)
End with
For each c in activesheet.range("h1:h"&LR)
If c.value<>"" and c.value<>0 then
C.offset(0,-2).value=c.value
End if
Next c
End sub
ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy