Results 1 to 3 of 3

Thread: [RESOLVED] Using Offset in VBA

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2009
    Posts
    32

    Resolved [RESOLVED] Using Offset in VBA

    Hi this is probably quite simple but I can't get anything to work!
    Basically I have two sheets.
    In Sheet 1 a list of data with columns A and B the important ones.
    In sheet 2 a summary of the data
    I want to look in sheet 1 at column B and see if the variable is the letter "A"
    If so I want it to look back at column A on that row which contains a number
    I want to paste that number into sheet 2 at a specified cell
    There are several rows of data and the letter "A" can occur more than once.
    Everytime it does, it should repeat the number look up and paste it in sheet 2 below the previous one.
    I know its offset but it will not loop round
    Thanks in advance

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Using Offset in VBA

    you can try like
    vb Code:
    1. targetrow = 2
    2. targetcol = 4
    3. for each c in sheet("sheet1").range("b1:b99")   ' change to suit
    4.   if c.value = "A" then sheets("sheet2").cells(targetrow, targetcol) = c.offset(, -1) : targetrow = targetrow + 1
    5. next
    change target and ranges to suit,
    dim c as range
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2009
    Posts
    32

    Re: Using Offset in VBA

    Brilliant
    Thanks very much it works a treat

Posting Permissions

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



Click Here to Expand Forum to Full Width