Results 1 to 17 of 17

VBA-Perform lookup for all rows in column if date selected?

Threaded View

  1. #1
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Question VBA-Perform lookup for all rows in column if date selected?

    I am hoping to find a way to select a date at the top of a column and perform a look for all of the cells below it, and a different lookup for those one row to the right.

    I have copied a bunch of things found and then went through chatgpt but what I'm getting from it isn't working. I originally was going to do this with xlookups on all of the cells which I finally got working, but the data behind it is huge and the user wont need all of them.

    I've attached an example and the code I have is below. Also below are the formulas that work to pull the data in case that helps.


    Left Column:'=XLOOKUP($D7&TEXT($E$6, "mm/dd/yyyy"),data[Helper], data[Result],0,0)  &  Right Column:'=XLOOKUP($D7&TEXT($K$6, "mm/dd/yyyyy"),data[Helper],data[Day]&CHAR(10)&TEXT(data[time], "hh:mm"))
    Sub loaddata()
    
    Dim ActiveCell As Range
    Dim Lookup1 As Variant
    Dim Lookup2 As Variant
    Dim ec As Range
    Dim Result As Variant
    Dim ws As Workbook
    Dim sc As Range
    Dim ic As Range
    Set sc = ThisWorkbook.Worksheets("data").Range("Helper")
    Set ec = Sheets("data").Range("Day")
    Set tc = Sheets("data").Range("Time")
    Set res = Sheets("data").Range("Res")
    Set ActiveCell = ActiveCell
    
    'If Date selected in Row 5, perform for the two columns below
    'how to set format for time hh:mm?
    Lookup1 = LookupValue = ActiveCell.Offset(0, -1).Value
    Lookup2 = ActiveCell.EntireColumn.Rows(3)
    
    On Error Resume Next
    'Primary Column Result
    Result = Application.WorksheetFunction.XLookup(Lookup1 & Lookup2, sc, ec)
    'One column to the right
    Result = Application.WorksheetFunction.XLookup(Lookup1 & Lookup2, sc, res & tc)
    
    On Error GoTo 0
    
    If Not IsError(Result) Then
    ActiveCell.Value = Result
    Else: MsgBox "Didn't work"
    
    End If
    
    
    End Sub
    Attached Files Attached Files
    Last edited by Anita Knapp; 09-22-2023 at 08:48 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA to perform sum of column values if number of rows and columns are not constant
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-17-2015, 09:40 AM
  2. Replies: 12
    Last Post: 08-12-2014, 02:49 PM
  3. [SOLVED] Perform calculations for multiple rows based on specific column text
    By justinmirsky in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 03-31-2013, 08:20 PM
  4. Perform a two column lookup that returns a value from another column?
    By okstate1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2010, 07:13 PM
  5. Replies: 4
    Last Post: 01-17-2008, 06:05 PM
  6. Replies: 2
    Last Post: 08-02-2006, 04:40 PM
  7. [SOLVED] How do you perform a two-column lookup?
    By Kymm in forum Excel General
    Replies: 5
    Last Post: 10-20-2005, 01:05 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