InStr problem

Alexandro88

New Member
Joined
Nov 11, 2010
Messages
35
Code:
If [COLOR="Red"]Myday = InStr(1, Left(rngcell.Value, 5), "Sun" Or "Sat" Or "Mon" Or "Tue" Or "Wed" Or "Thu" Or "Fri")[/COLOR] Then
         If InStr(1, Left(rngcell.Value, 3), "LRR") Then
            Cells.Value = lr_Total
         ElseIf InStr(1, Left(rngcell.Value, 3), "OP3") Then
            Cells.Value = zResult_Total_NSOP
         ElseIf InStr(1, Left(rngcell.Value, 3), "OP4") Then
            Cells.Value = vResult_Total_NSOP
         ElseIf InStr(1, Left(rngcell.Value, 3), "OL3") Then
            Cells.Value = vResult_Total_NSOL
         ElseIf InStr(1, Left(rngcell.Value, 3), "OL4") Then
            Cells.Value = zResult_Total_NSOL
         End If
    End If

I get erro for the red line. Can anyone help me and provide solution to me?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Perhaps

Code:
Myday = Left(rngcell.Value, 3)
If Myday = "Sun" Or Myday = "Sat" Or Myday = "Mon" Or Myday = "Tue" Or Myday = "Wed" Or Myday = "Thu" Or Myday = "Fri" Then
 
Upvote 0
What are you trying to do exactly? You will have to repeat for each string eg:

Code:
If Myday = InStr(1, Left(rngcell.Value, 5), "Sun") Or Myday = InStr(1, Left(rngcell.Value, 5), "Sat") Then
 
Upvote 0
Code:
LValue = Format(Cells(1, 17).Value, "d - mmm - yy")
Myday = Format(LValue, "dddd")

 
If Myday = InStr(1, Left(rngcell.Value, 5), "Sun" Or "Sat" Or "Mon" Or "Tue" Or "Wed" Or "Thu" Or "Fri") Then
         If InStr(1, Left(rngcell.Value, 3), "LRR") Then
            Cells.Value = lr_Total
         ElseIf InStr(1, Left(rngcell.Value, 3), "OP3") Then
            Cells.Value = zResult_Total_NSOP
         ElseIf InStr(1, Left(rngcell.Value, 3), "OP4") Then
            Cells.Value = vResult_Total_NSOP
         ElseIf InStr(1, Left(rngcell.Value, 3), "OL3") Then
            Cells.Value = vResult_Total_NSOL
         ElseIf InStr(1, Left(rngcell.Value, 3), "OL4") Then
            Cells.Value = zResult_Total_NSOL
         End If
 End If


I want to find column that match with the date.
 
Upvote 0
Yes.

I want to find which column date that equal with actual date.
Then i want pump in the data in that column
 
Upvote 0
You can use the Match WorksheetFunction to find the position of a value within a range. I don't know where your range is , so I'll post an example that uses an array:

Code:
Sub Test()
    Dim Days As Variant
    Dim Myday As String
    Dim Col As Long
    Days = Array("Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri")
    Myday = Format(Cells(1, 17).Value, "ddd")
    Col = WorksheetFunction.Match(Myday, Days, False)
    MsgBox Col
End Sub
 
Upvote 0
Worksheets("Calc").Activate

For Each rngcell In Range("A1:DI" & Range("A" & Rows.Count).End(xlUp).Row)
If Myday = InStr(1, Left(rngcell.Value, 5), "Sun" Or "Sat" Or "Mon" Or "Tue" Or "Wed" Or "Thu" Or "Fri") Then
If InStr(1, Left(rngcell.Value, 3), "LRR") Then
Cells.Value = lr_Total
ElseIf InStr(1, Left(rngcell.Value, 3), "OP3") Then
Cells.Value = zResult_Total_NSOP
ElseIf InStr(1, Left(rngcell.Value, 3), "OP4") Then
Cells.Value = vResult_Total_NSOP
ElseIf InStr(1, Left(rngcell.Value, 3), "OL3") Then
Cells.Value = vResult_Total_NSOL
ElseIf InStr(1, Left(rngcell.Value, 3), "OL4") Then
Cells.Value = zResult_Total_NSOL
End If
End If

Next
 
Upvote 0

Forum statistics

Threads
1,222,441
Messages
6,166,056
Members
452,010
Latest member
triangle3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top