Solved

Need to get postion of a value that is found

Posted on 2013-11-20
7
410 Views
Last Modified: 2013-11-20
Almost there. This should the last part of this sub routine that needs to be modified.

Please refer to the comments in the code below.
'A1 - When the "cell.Value" is found get it's Row and Column position    AND
'
'Put the value x from the "Data" sheet acquired by the line...
'    "x = Application.VLookup(s, Worksheets("Data").Range("A:XFD"), 5, 0"
'to the postion found (specified comment A1) which will be in the "DRA Summary" sheet one row above

Sub Get_GQnumber1()
    Dim rng As Range, cell As Range
    Dim lc As Long
    Dim s As String, x As String
    With Worksheets("DRA Summary")
    lc = .Cells(3, Columns.Count).End(xlToLeft).Column

    Set rng = .Range(.Cells(3, 1), .Cells(3, lc))
       
    For Each cell In rng
        If cell.Value Like "GQ-*" Then
            MsgBox cell.Value
            s = Left(cell.Value, InStr(1, cell.Value & " ", " ") - 1)
'A1 - When the "cell.Value" in the "DRA Summary" sheet is found then get it's Row and Column position

            On Error Resume Next
                       
            x = Application.VLookup(s, Worksheets("Data").Range("A:XFD"), 5, 0)
           
'Put the value x from the "Data" sheet acquired by the line...
'    "x = Application.VLookup(s, Worksheets("Data").Range("A:XFD"), 5, 0"
'to the postion found (specified comment A1) which will be in the "DRA Summary" sheet one row above
           
        End If
    Next
    End With
End Sub


Your help with this is greatly appreciated.
Thanks.
0
Comment
Question by:tesla764
  • 3
  • 2
  • 2
7 Comments
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 20 total points
ID: 39663250
you can use

cell.row
cell.column

and

cell.value=x
0
 
LVL 4

Accepted Solution

by:
yuppydu earned 480 total points
ID: 39663274
Is this what you need?
Sub Get_GQnumber1()
    Dim rng As Range, cell As Range
    Dim lc As Long
    Dim s As String, x As String
   
    With Worksheets("DRA Summary")
   
    lc = .Cells(3, Columns.Count).End(xlToLeft).Column

    Set rng = .Range(.Cells(3, 1), .Cells(3, lc))
       
    For Each cell In rng
        If cell.Value Like "GQ-*" Then
            MsgBox cell.Value
            s = Left(cell.Value, InStr(1, cell.Value & " ", " ") - 1)
'A1 - When the "cell.Value" in the "DRA Summary" sheet is found then get it's Row and Column position

            On Error Resume Next
                       
            x = Application.VLookup(s, Worksheets("Data").Range("A:XFD"), 5, 0)
           
'Put the value x from the "Data" sheet acquired by the line...
'    "x = Application.VLookup(s, Worksheets("Data").Range("A:XFD"), 5, 0"
'to the postion found (specified comment A1) which will be in the "DRA Summary" sheet one row above
            cell.Offset(-1, 0) = x
        End If
    Next
    End With
End Sub
0
 

Author Comment

by:tesla764
ID: 39663305
I will try these suggestions now. I will let you know as soon as I test them.
Thanks.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 4

Expert Comment

by:yuppydu
ID: 39663309
BTW format your code, it is easier to read

Sub Get_GQnumber1()
    Dim rng As Range, cell As Range
    Dim lc As Long
    Dim s As String, x As String

    With Worksheets("DRA Summary")

        lc = .Cells(3, Columns.Count).End(xlToLeft).Column

        Set rng = .Range(.Cells(3, 1), .Cells(3, lc))

        For Each cell In rng
            If cell.Value Like "GQ-*" Then
                MsgBox cell.Value
                s = Left(cell.Value, InStr(1, cell.Value & " ", " ") - 1)

                On Error Resume Next

                x = Application.VLookup(s, Worksheets("Data").Range("A:XFD"), 5, 0)

                cell.Offset(-1, 0) = x
            End If
        Next
    End With
End Sub
0
 

Author Closing Comment

by:tesla764
ID: 39663360
Yuppydu, Thanks a billion. Looks like that works upon initial testing. Now we can move on. Kudos to you. You should have 480 points. I gave 20 to ssaqibh for participating. Which was the best way the system allowed me to share them.
Thank you to ssaqibh also your suggestion was appreciated.
Have a great day everybody.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39663398
You really do not have to give points for participating. The correct answer deserves full points and you should not deprive it of them.

Actually I had missed the part which said "one row above"
0
 
LVL 4

Expert Comment

by:yuppydu
ID: 39663443
Thanks, good day to you as well.
I have one question for you: why do you have a module for each sub?
Yuppydu
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article will show you how to use shortcut menus in the Access run-time environment.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now