Consulting

Results 1 to 5 of 5

Thread: Modify Code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Modify Code

    MdMack was able to provide me with the following code. See previous question
    It works perfectly for what I need.
    I just have another spreadsheet that can use this, but needs to be modified.

    [vba]
    Option Explicit
    Sub DoStuff() Dim wb As Workbook
    Dim ws As Worksheet
    Dim ThsSht As Worksheet
    Dim tgt As Range
    Dim Target As Range
    Dim MyPath As String

    MyPath = "C:\Docu\" '<=====Change to suit

    Application.ScreenUpdating = False
    Set ThsSht = ActiveSheet
    Set Target = ThsSht.Range("B6")
    Set wb = Workbooks.Open(MyPath & "Asset Tracking.xlsx")
    Set ws = wb.Sheets(ThsSht.Range("K5").Value)
    Set tgt = ws.Columns(2).Find(Target.Value)
    If tgt Is Nothing Then
    Set tgt = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1)
    tgt = Target.Value
    End If
    tgt.Offset(, 1) = ThsSht.Range("AA1").Value
    tgt.Offset(, 2) = ThsSht.Range("V1").Value
    wb.Close True
    Set wb = Nothing
    Application.ScreenUpdating = True
    End Sub
    [/vba]

    What I need is instead of looking at just B6 I need it to grab a range from "E10:E1500" and I don't need to do a find(Target.Value) one because it will run and take a very long time.

    Instead of
    [vba]Set ws = wb.Sheets(ThsSht.Range("K5").Value) [/vba]

    I need it to look at Range ("D10:1500") and match with sheet.
    If no match skip line.


    Now instead of
    [vba]tgt.Offset(, 1) = ThsSht.Range("AA1").Value[/vba]
    *This can be the same for all in the range it will be "D6"

    Now for
    [vba]tgt.Offset(, 2) = ThsSht.Range("V1").Value [/vba]

    I will need it to look at each row and grab the value in "O"
    Hope that explains my new goal.

    Thanks
    Last edited by mdmackillop; 12-09-2008 at 10:56 AM. Reason: Link added

Posting Permissions

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