?
Solved

Use a variable to find and name another.

Posted on 2014-08-06
4
Medium Priority
?
80 Views
Last Modified: 2014-08-06
I have a variable named SurfCH_Value
What I need to do is in column M, find the cell that has its value in it.  Then when that is found, (will be there everytime) I need to assign another variable to the value of the cell that is offset 4 cells from that to the right.  Naming that variable CH_FixedValueForSurf

I need to use this name later in the procedure...  new to the naming of items within VBA to use later..  opening up a lot more understanding of how to use and write subs.
0
Comment
Question by:RWayneH
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
MacroShadow earned 2000 total points
ID: 40244389
Try this:
Sub Demo()

    Dim SurfCH_Value
    Dim CH_FixedValueForSurf

    Dim rng As Range
    Dim c As Range
    
    ' Here you asign the value to the "SurfCH_Value" variable
    SurfCH_Value = "TEST_VALUE"
    
    Set rng = Range("M1:M" & Range("M1").End(xlDown).Row)

    For Each c In rng
        If c.Value = SurfCH_Value Then
            ' Here you asign the value to the "CH_FixedValueForSurf" variable
            CH_FixedValueForSurf = c.Offset(0, 4).Value
            Exit For
        End If
    Next

End Sub

Open in new window

0
 

Author Comment

by:RWayneH
ID: 40244513
Hey thanks!!
One more quick thing, how would I at the end concatenate SurfCH_Value with CH_FixedValueForSurf and give that a variable name?
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40244574
No points...

in VBA:
New_Variable_Name = SurfCH_Value & CH_FixedValueForSurf
0
 

Author Closing Comment

by:RWayneH
ID: 40244605
EXCELlent !!  Thank you very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

850 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