Solved

Need to get postion of a value that is found

Posted on 2013-11-20
7
442 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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