+ Reply to Thread
Results 1 to 7 of 7

To find a value in a row then to offset values based on code. *tricky*

Hybrid View

ExcelNewblet To find a value in a row then... 02-27-2015, 10:50 AM
stnkynts Re: To find a value in a row... 02-27-2015, 11:17 AM
ExcelNewblet Re: To find a value in a row... 02-27-2015, 11:28 AM
stnkynts Re: To find a value in a row... 02-27-2015, 11:51 AM
ExcelNewblet Re: To find a value in a row... 02-27-2015, 12:01 PM
stnkynts Re: To find a value in a row... 02-27-2015, 12:23 PM
ExcelNewblet Re: To find a value in a row... 02-27-2015, 12:25 PM
  1. #1
    Registered User
    Join Date
    02-27-2015
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    5

    Smile To find a value in a row then to offset values based on code. *tricky*

    Hi Guys Newblet here

    What I am trying to accomplish is to find the column header "VPD" and to offset a character under an array of codes.
    I am unable to offset the values properly any help would be appreciated. Sorry if this is a "newbie question"
    Code is below



    Sub VisitsperDay()


    Dim sht As Worksheet
    Dim LastColumn As Long, Vpd As Variant, c As Range, Visits As Variant, vcount As Long, cell As Variant

    With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual

    Columns("A:AD").Select
    Set cell = Selection.Find(What:="VPD", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SeachFormat:=False)

    Vpd = "V"
    Visits = Array("H175", "H200", "H209", "H300", "H400", "H600", "K100", "K200", "K305", "B200", "B401", "B500")



    For Each c In Intersect(Range("C:C"), ActiveSheet.UsedRange)
    For vcount = LBound(Visits) To UBound(Visits)
    If c.Value = Visits(vcount) Then
    c.Offset(0, cell) = Vpd
    Exit For
    Exit For
    End If


    Next
    Next

    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic


    End With

    End Sub
    Last edited by ExcelNewblet; 02-27-2015 at 03:48 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: To find a value in a row then to offset values based on code. *tricky*

    It is not clear to me what you are trying to do but I will point out where it is wrong.

    Set cell = Selection.Find(What:="VPD", After:=ActiveCell, LookIn:=xlFormulas, _
     LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
     MatchCase:=False, SeachFormat:=False)
    The above code is going to return a range. Because you set the search parameters as "VPD", the variable cell will return a value of "VPD".

    c.Offset(0, cell) = Vpd
    saying "cell" is the same as telling the code cell.value, which as described above is "VPD". So you are trying to offset by the string "VPD" rather than a numerical value ie

    c.Offset(0, "VPD") = Vpd
    If you want an answer to your main problem, submit an example workbook which clearly shows what you want to accomplish.

  3. #3
    Registered User
    Join Date
    02-27-2015
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    5

    Re: To find a value in a row then to offset values based on code. *tricky*

    Thank you for the response

    I attached an example of what I am trying to accomplish
    Thanks for helping me understand the search code I have added.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: To find a value in a row then to offset values based on code. *tricky*

    You workbook example only has data, not any example of what you want to accomplish. Explain what you want like I am five years old.

  5. #5
    Registered User
    Join Date
    02-27-2015
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    5

    Re: To find a value in a row then to offset values based on code. *tricky*

    Okay

    In the workbook I attached I marked a V under the VPD Column that I want to increment for every visit code

    Visits = Array("H175", "H200", "H209", "H300", "H400", "H600", "K100", "K200", "K305", "B200", "B401", "B500")

    Sorry if I didn't illustrated well enough

    For Each c In Intersect(Range("C:C"), ActiveSheet.UsedRange) ---> Column containing the codes
    For vcount = LBound(Visits) To UBound(Visits)
    If c.Value = Visits(vcount) Then
    c.Offset(0, I want to add the location where VPD(header) is ) = Vpd <----- then add a V for every code captured as a visit ( that way I can have a count)

    I could add the location and count the columns but I wanted to find a solution to dynamically update itself on which column VPD (header) resides because it can change depending on codes/

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: To find a value in a row then to offset values based on code. *tricky*

    There is no value in any cell in column C that is in the array Visits and as such there is no scenario where the if statement will be true. As such the proceding line of code will never be considered.

    Your explanation is still lacking and unfortunately I am not going to be able to assist you anymore. I wish you the best of luck in finding the solution to your problem.

  7. #7
    Registered User
    Join Date
    02-27-2015
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    5

    Re: To find a value in a row then to offset values based on code. *tricky*

    I had to delete some things its obvious the codes are in column A

    Easy fix problem solved

    Set aCell = ActiveSheet.UsedRange.Find(What:=strCol, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)


    For Each c In Intersect(Range("C:C"), ActiveSheet.UsedRange)
    For vcount = LBound(Visits) To UBound(Visits)
    If c.Value = Visits(vcount) Then
    c.Offset(0, aCell.Column - 2) = Vpd
    Exit For
    Exit For
    End If
    Last edited by ExcelNewblet; 02-27-2015 at 03:51 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy and PasteSpecial Values after Find and Offset
    By SteveG1965 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2013, 06:35 AM
  2. Replies: 1
    Last Post: 04-19-2013, 08:30 PM
  3. code to find text, offset 1 column and paste to new workbook not working
    By trillium in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2011, 07:55 AM
  4. Help with find, copy, and paste code using offset
    By mundellj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2011, 08:16 PM
  5. Code To Find and Offset works on first sheet but won't loop to other sheets
    By mgaworecki in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2009, 03:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1