|
-
Oct 1st, 2010, 02:38 AM
#1
Thread Starter
Member
[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
-
Oct 1st, 2010, 04:11 AM
#2
Re: Using Offset in VBA
you can try like
vb Code:
targetrow = 2 targetcol = 4 for each c in sheet("sheet1").range("b1:b99") ' change to suit if c.value = "A" then sheets("sheet2").cells(targetrow, targetcol) = c.offset(, -1) : targetrow = targetrow + 1 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
-
Oct 1st, 2010, 05:48 AM
#3
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|