+ Reply to Thread
Results 1 to 2 of 2

Where can I find sample VBA code...

  1. #1
    Registered User
    Join Date
    03-05-2005
    Posts
    8

    Where can I find sample VBA code...

    Although I am a programmer, I have not written VBA code. I need to do the following:

    Loopk thru a range of cells (I assume this is treated as an array) and when I find a specific value in the current cell I want to change that value to the value in a cell outside the array.

    Is there a good place to find sample code that does something resembling what I want to do?

    Thanks,

    Pete

  2. #2
    Forum Contributor
    Join Date
    09-05-2004
    Location
    Melbourne
    Posts
    193
    One of the best places for finding example code is (believe it or not) the VBA Help. The Help files contain small snipets of code to explain most objects, properties, methods and events. The next step would be to search for Excel MVP websites using a search engine. A number of MVP's wil provide links to other MVP websites. For your specific need, the following code may prove to be sufficient.

    Sub ChangeValue()

    With Worksheets("MySheet").Range("A1:A100")
    Set c = .Find(MyValue, Lookin:=xlValues)
    Do While Not c Is Nothing
    c.Value = Worksheets("MySheet").Range("B1").Value
    set c = .FindNext(c)
    Loop
    End With

    End Sub

    Replace 'MySheet', 'MyValue' with the appropriate sheet and value you want replaced and the Ranges according to your needs. This is a small adjustment to example code given in the VBA Help files for a search on 'Find'.

    HTH
    Last edited by richardreye; 03-07-2005 at 06:15 PM. Reason: Error in code

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1