looping a code

Joined
Dec 4, 2008
Messages
1
Reaction score
0
so i've got a spreadsheet that i'm trying to automate and i'm trying to get it to loop the below code until it reaches a blank. what it does is takes cell H1 and checks to see if there are any cells that match in A:A. if it finds a match, it copies the cell above it, then pastes it in the next blank cell in column J.

i can get it to run for cell H1 fine, but how do i get it to check for H2,H3,H4...etc. ? basically to repeat the search/copy/paste for all cells in column H.


Public Sub LoopRow()
Dim c As Range

For Each c In Range("A:A")

If c.Value = Range("H1") Then
c.Offset(-1, 0).Copy
Columns("J:J").Select
Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
ActiveCell.Select
ActiveSheet.Paste
End If

Next c





End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top