Solved

Need to get postion of a value that is found

Posted on 2013-11-20
7
435 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

832 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