Solved

Need to get postion of a value that is found

Posted on 2013-11-20
7
452 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

689 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