last day (15 days later) » 

5:00 PM
2
A: Modifying VBA copy and paste code to search down rather than across

BGeorgeAssuming I understand your desire correctly, you can use the .Offset method with your current range to get to the cell below it. You would need to add a dim, so here's my stab at what you're trying to accomplish: Sub test() Dim NameValue As String, w1 As Worksheet, w2 As Worksheet 'new local va...

 
114
Thanks! Just to be clear, what is being searched for with "FIND ME" and "NAME:"? Before there were only two inputs and now there are three (those two and DATE OF BIRTH).
The reason I ask is that unfortunately I can't get the program to work as intended.
 
The way you have written your code, a cell in row A would need to have the exact text "NAME:" for your code to pick it up. My code works the same way, a cell in row A would need to have the exact text "FIND ME" for the newValue to be set to the value of the cell below it.
 
114
Thanks George. What I mean is before I would only have to enter NAME: and DATE OF BIRTH: - what role is the third value FIND ME playing? Currently I'm just putting in 'A', 'A', 'B' (for example) for those three values.
 
I wrote the FIND ME third value in there because that's what I thought you meant when you said "what I'd like to do is check whether a certain string exists, if it does grab the entry directly BELOW it, and then continue searching for the next string and associated entry just like the code does already." The certain string I wrote code to search for was "FIND ME" and the then continue searching for the next string I took to mean that you wanted this new search before your existing code.
 
114
Thanks, sorry for the confusion! I see where the issue is now. What I'd actually like to do is search for the first string "NAME:" as usual, but, once found, select the cell below it rather than the cell beside it. Then as usual the program would continue and check for the "DATE OF BIRTH:" string and place the value beside it in the new sheet. I'll need to be more careful about my phrasing in the future.
 
5:00 PM
@114 Thanks for the clarification. See my updated answer, hopefully this is much closer to what you actually asked for in the first place! :)
 
114
I think we're getting closer, but I get an error at lookin:xlValues. The error is "Compile error: Expected: list separator or)". Once that's fixed I should be able to test it out. +1 for code that's much clearer than my initial code.
 
@114 Change lookin:xlValues to lookin:=xlValues. I'll update my answer as well.
 
114
Fixed. I'm now getting a 'subscript out of range' error. I've verified that the sheet names and search terms are correct. UPDATE: No specific location highlighted when error occurs, message simply comes up.
 
If you need help fixing the errors, you will need to say where you are getting the error so I can help.
 
114
And error occurs immediately, no wait time.
 
5:01 PM
Hey @114 I'm working on the code now.
Do you have a worksheet called "Sheet1" and a worksheet called "Sheet2"? That might be your problem.
Change the part where you are setting the worksheets to the actual names of your worksheets. "Sheet1" and "Sheet2" were just placeholders for your worksheet names.
 
114
Yep, well, I have one named Sheet1 and renamed Sheet2 to the correct name
 
Do you have other errors?
 
114
So now I'm receiving a different error "Object Required: Set searchRange = w1.Range("A" & Rows.Count).End(xlUp).row"
 
Try changing that to Set searchRange = w1.Range("A1").EntireColumn
 
114
great, that fixed up that error
I get the same error now down at outRange.value = item.Key
 
5:20 PM
ok slight change. declare three new variables: dim items, keys, as variant and dim i as integer.
then say:
keys = resultsDictionary.Keys
items = resultsDictionary.Items
now loop do this for loop:
for i = 1 to items.count
outRange.value = key(i)
set outRange = outRange.Offset(0,1)
outRange.value = item(i)
set outRange = outRange.Offset(1,-1)
next i
 
114
where should that loop go?
instead of the last loop right?
 
it should replace the for each loop in my answer.
Yep
 
114
for "Dim resultsDictionary As Object" I get "Duplicate declaration in current scope"
 
Delete that second declaration then.
also, move the 'resultsDictionary.add' part of the code to just beneath the 'Do'
 
114
done
I get another object required error at the new variable
"keys = resultsDictionary.keys"
(also I modified key(I) in your loop to keys since key wasn't defined)
 
5:31 PM
looking into it...
Dim outRange As Range
Dim items, keys
Set outRange = w2.Range("A1")
keys = resultsDictionary.keys
items = resultsDictionary.items
For i = 1 To resultsDictionary.Count
outRange.value = keys(i - 1)
Set outRange = outRange.Offset(0, 1)
outRange.value = items(i - 1)
Set outRange = outRange.Offset(1, -1)
Next i
End Sub
 
114
thanks, now I get the error Key is already associated with an element of this collection for "resultsDictionary.Add Key:=c.Offset(1, 0).value, item:=d.value"
think we're making progress
 
Also, change this line of code resultsDictionary.Add Key:=c.Offset(1,0).value, item:=d.value to
resultsDictionary.Add Key:=c.Offset(1,0).value, item:=d.offset(0,1).value
I'm glad I could point you in the right direction. I need to sign out, I've spent way too much work time on your problem. Good luck!
Keep searching google and SO for answers.
I'd appreciate it if you would accept my answer if it ends up being your solution. I really tried hard to make it work for you.
 
114
thanks for your help, I'll try to see if I can get it working
 
I gave you some comment and question points to help offset the bounty.
Have fun, it will feel so good to get it working!
 
114
5:50 PM
Thanks, one thing that might help is if you're able to add the changes from here into your code in the question / keep troubleshooting it if you have some time
there's 6 days to award the bounty so it's not as though it needs to work perfectly today
 

last day (15 days later) »