+ Reply to Thread
Results 1 to 2 of 2

Need help to lookup through each cells in a range based on two condition

Hybrid View

  1. #1
    Registered User
    Join Date
    07-02-2019
    Location
    Surabaya, Indonesia
    MS-Off Ver
    Ms. Office 2007
    Posts
    8

    Need help to lookup through each cells in a range based on two condition

    what am i trying to do here is simply just like the gantt chart i want to write into a cell in range that meet two conditions, but got an error runtime 13: type mismatch, i still can figure it out what is wrong with the code, and can you show me how to loop through each row from column name in worksheet "dtbs"...
    here is the workbook that i've been working on....
    Option Explicit
    Private Sub cbInput_Click()
    Dim rg As Range
    Dim x As String
    Dim yA As Variant
    Dim yB As Variant
    Dim yC As Variant
    Dim yD As Variant
    Dim txA As String
    Dim txB As String
    Dim txC As String
    Dim txD As String
    Srkp.Activate
    Set rg = Range("D9:AH14")
    rg.Activate
    Selection.VerticalAlignment = xlCenter
    Selection.HorizontalAlignment = xlCenter
    
    txA = Sheets("dtbs").Cells(2, 3).Value 'For_S
    txB = Sheets("dtbs").Cells(2, 4).Value 'For_I
    txC = Sheets("dtbs").Cells(2, 5).Value 'For_T
    txD = Sheets("dtbs").Cells(2, 6).Value 'For_C
    
    x = Sheets("dtbs").Cells(2, 2).Value
    '============================================
    'On Error Resume Next
    If InStr(txA, ",") Then
        For Each yA In Split(txA, ",")
            rg.Cells(x, yA).Value = "S"
        Next yA
    Else
        yA = txA
            rg.Cells(x, yA).Value = "S"
    End If
    '============================================
    'On Error Resume Next
    If InStr(txB, ",") Then
        For Each yB In Split(txB, ",")
            rg.Cells(x, Val(yB)).Value = "I"
        Next yB
    Else
        yB = txB
            rg.Cells(x, Val(yB)).Value = "I"
    End If
    '============================================
    'On Error Resume Next
    If InStr(txC, ",") Then
        For Each yC In Split(txC, ",")
            rg.Cells(x, Val(yC)).Value = "T"
        Next yC
    Else
        yC = txC
            rg.Cells(x, Val(yC)).Value = "T"
    End If
    '============================================
    'On Error Resume Next
    If InStr(txD, ",") Then
        For Each yD In Split(txD, ",")
            rg.Cells(x, Val(yD)).Value = "C"
        Next yD
    Else
        yD = txD
        rg.Cells(x, Val(yD)).Value = "C"
    End If
    
    cmbBox_Month.Value = cmbBox_Month.Value
    cmbBox_X.SetFocus
    Unload Me
    End Sub
    Attached Files Attached Files
    Last edited by petroes; 05-07-2020 at 05:20 AM. Reason: showing code in question

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,313

    Re: Need help to lookup through each cells in a range based on two condition

    Place as your very first line in the UserForm module 'Option Explicit'
    Then run debug, as each fault shows, declare any variables (Dim) immediately under the line 'Option Explicit'
    You will also find a number of typo's, once you have done this resubmit your code, we will try to help then.
    Help us to help you, run debug, proof reading is tedious & time wasting for me.

+ 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. [SOLVED] Sum Excel Cells in a Range based on condition in first column
    By ancoach in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 03-19-2020, 02:20 PM
  2. [SOLVED] How to Count specific words in a range of cells based on condition
    By Ell0ll in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-19-2020, 05:13 PM
  3. counting blank cells in range based on condition using another column
    By TheBlueBell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2013, 04:58 PM
  4. Counting the number of empty cells based on a condition in a range
    By naga in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-01-2013, 10:01 AM
  5. [SOLVED] Color cells in Range based on condition.
    By gammaman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-24-2012, 10:27 AM
  6. VBA code to select cells, row by row in range, based on condition
    By Vera22 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-31-2012, 11:12 AM

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