Find Value in Range then copy that to a new worksheet Loop

mjmarian1

New Member
Joined
Apr 5, 2016
Messages
2
I have an excel spread sheet that has account information for users. There are multiple occurrences of a value in column B that say "Account Name:" and I need to copy the value that is next to it in Row D and paste it in Column A of a different worksheet in that workbook called Data. I need to repeat this in a range from B1:B20000. I cant get it to move past the first occurrence of the value "Account Name:" and I also don't know how to make it check to see if there is value in the first cell on the worksheet called Data is blank to paste that value into.

PHP:
Dim aN As RangeSet aN = Range("B1:B20000")


    'Loop through every used cell in the active worksheet
    For Each aN In ActiveSheet.UsedRange
           
        If ActiveCell = "Account Name:" Then
           ActiveCell.Offset(0, 2).Select
           ActiveCell.Copy
           Sheets("Data").Select
           ActiveCell.PasteSpecial
           Sheets("Table4").Select
           ActiveCell.Offset(0, -2).Select
        Else: ActiveCell.Offset(1, 0).Select
        
       End If
       
    Next
 End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try:
Code:
Sub CopyCell()
    Application.ScreenUpdating = False
    Dim sAddr As String
    Dim foundAN As Range
    Set foundAN = Range("B:B").Find("Account Name", LookIn:=xlValues, lookat:=xlWhole)
    If Not foundAN Is Nothing Then
        sAddr = foundAN.Address
        Do
            foundAN.Offset(0, 2).Copy Sheets("Data").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
            Set foundAN = Range("B:B").FindNext(foundAN)
        Loop While foundAN.Address <> sAddr
        sAddr = ""
    End If
    Set foundAN = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,216,816
Messages
6,132,857
Members
449,761
Latest member
AUSSW

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top