Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the following code that lists Numerical Values in Column C that are = to a Textbox Value,
But As the Values are Anywhere Between 2-22 rows Below the Value in Column A, i have been unable to gain this value from Column A and be able to use this to be the Value of a Label when a CommandButton is pressed. The value is Identified in the Following Code, But i think i need to go Backwards to Find the Value, and have not been able to do this? Private Sub TextBox1_Change() Application.ScreenUpdating = False ListBox3.Clear If TextBox1.Value < "" Then Dim lastcell As Long Dim myrow As Long Dim i As Long On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "A").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell If .Cells(myrow, 1) < "" Then ' <=== THIS IS THE VALUE HERE I NEED TO IDENTIFY If .Cells(myrow, 1).Offset(-1, 2).Value = ListBox1.Value Then If .Cells(myrow, 1).Offset(-1, 6).Value = ListBox2.Value Then For i = 2 To 22 If .Cells(myrow, 3).Offset(i, 0).Font.Strikethrough = False And Cells(myrow, 3).Offset(i, 0).Value < "" _ And IsNumeric(.Cells(myrow, 3).Offset(i, 0)) Then If .Cells(myrow, 3).Offset(i, 0).Value < "" And .Cells(myrow, 3).Offset(i, 0).Value = Val(TextBox1.Value) Then ListBox3.AddItem Cells(myrow, 3).Offset(i, 0) ListBox3.List(ListBox3.ListCount - 1, 1) = Cells(myrow, 3).Offset(i, 0).Address End If End If Next i End If End If End If Next End With End If Label8 = ListBox3.ListCount Application.ScreenUpdating = True End Sub Want to do something like: |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rest of Message(sent accendently before completing
Private Sub CommandButton2_Click() Label7 = ListBox3.Value Application.ScreenUpdating = True End Sub Corey.... |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Got a Little Further:
Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = 2 To 22 If .Cells(myrow, 3).Offset(i, -2).Value < "" Then If IsNumeric(.Cells(myrow, 3).Offset(i, -2)) = True Then Label7 = .Cells(myrow, 3).Offset(i, -2).Value End If End If Next i End If End If Next End With Application.ScreenUpdating = True End Sub But the Value is in Column A but it is not the Correct Value? "Corey" wrote in message ... Rest of Message(sent accendently before completing Private Sub CommandButton2_Click() Label7 = ListBox3.Value Application.ScreenUpdating = True End Sub Corey.... |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you want to walk backwards from the first row that is = Textbox1 in
column C until you find a number in column A, then put that number in Label7 and quit looking: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long Dim bExit as Boolean On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell bExit = False If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = MyRow To 2 step - 1 If .Cells(i, 1).Value < "" Then If IsNumeric(.Cells(i, 1)) = True Then Label7 = .Cells(i, 1).Value bExit = True End If End If if bExit then exit for Next i End If End If if bExit then exit for Next myrow End With Application.ScreenUpdating = True End Sub -- Regards, Tom Ogilvy "Corey" wrote in message ... Got a Little Further: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = 2 To 22 If .Cells(myrow, 3).Offset(i, -2).Value < "" Then If IsNumeric(.Cells(myrow, 3).Offset(i, -2)) = True Then Label7 = .Cells(myrow, 3).Offset(i, -2).Value End If End If Next i End If End If Next End With Application.ScreenUpdating = True End Sub But the Value is in Column A but it is not the Correct Value? "Corey" wrote in message ... Rest of Message(sent accendently before completing Private Sub CommandButton2_Click() Label7 = ListBox3.Value Application.ScreenUpdating = True End Sub Corey.... |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom,
The value placed in Textbox1 is a Minimum Value i need to find in the Column C. It represents various lengths contained in a roll Each roll has a unique Numerical ID (Column A) There can be up to 20 separate values in each Column A roll ID I have code that can find a value = Textbox1 value, But i need to identify the Column A Value that is Accociated to that minumum value(it will be in Column C I tried your code I get a Value that is in Column A, but ALWAYS the 1st value, Not the Value associated to the Listbox3 value Corey.... "Tom Ogilvy" wrote in message ... If you want to walk backwards from the first row that is = Textbox1 in column C until you find a number in column A, then put that number in Label7 and quit looking: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long Dim bExit as Boolean On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell bExit = False If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = MyRow To 2 step - 1 If .Cells(i, 1).Value < "" Then If IsNumeric(.Cells(i, 1)) = True Then Label7 = .Cells(i, 1).Value bExit = True End If End If if bExit then exit for Next i End If End If if bExit then exit for Next myrow End With Application.ScreenUpdating = True End Sub -- Regards, Tom Ogilvy "Corey" wrote in message ... Got a Little Further: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = 2 To 22 If .Cells(myrow, 3).Offset(i, -2).Value < "" Then If IsNumeric(.Cells(myrow, 3).Offset(i, -2)) = True Then Label7 = .Cells(myrow, 3).Offset(i, -2).Value End If End If Next i End If End If Next End With Application.ScreenUpdating = True End Sub But the Value is in Column A but it is not the Correct Value? "Corey" wrote in message ... Rest of Message(sent accendently before completing Private Sub CommandButton2_Click() Label7 = ListBox3.Value Application.ScreenUpdating = True End Sub Corey.... |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
First, you should make a copy of your workbook and test any code I post in
that copy so your original code is not disturbed. This should be your normal practice for any help you get from anyone. Frankly, your descriptions require quite a bit of interpretation and code provided could be off the mark (based on incorrect intepretations). This is what I understand you to say: Assuming the value in Textbox1 only occurs in a single cell in Column C and you want to find the value in column A of that row: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim rng as Range Dim rng1 as Range lastcell = Worksheets("InspectionData") _ .Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") set rng1 = .Range("C1:C" & lastrow) End with set rng = rng1.Find( _ what:=Textbox1.Value, _ After:=rng1(rng1.count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) if not rng is nothing then Label7.Caption = rng.offset(0,-2) else Label7.Caption = "Not Found" end if Application.ScreenUpdating = True End Sub or same assumptions about the value in C being unique, then If your data is like this A C ID1 3 6 9 1 and you search for 1 in C and want to put ID1 in Label 7 Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim rng as Range Dim rng1 as Range lastcell = Worksheets("InspectionData") _ .Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") set rng1 = .Range("C1:C" & lastrow) End with set rng = rng1.Find( _ what:=Textbox1.Value, _ After:=rng1(rng1.count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) if not rng is nothing then if not Isempty(rng.offset(0,-2)) then Label7.Caption = rng.offset(0,-2).Value else label7.Caption = rng.offset(0,-2).End(xlup).Value end if else Label7.Caption = "Not Found" end if Application.ScreenUpdating = True End Sub You spoke about listbox3, but it has never appeared in your code, so I have no idea how that figures in. -- regards, Tom Ogilvy "Corey" wrote in message ... Tom, The value placed in Textbox1 is a Minimum Value i need to find in the Column C. It represents various lengths contained in a roll Each roll has a unique Numerical ID (Column A) There can be up to 20 separate values in each Column A roll ID I have code that can find a value = Textbox1 value, But i need to identify the Column A Value that is Accociated to that minumum value(it will be in Column C I tried your code I get a Value that is in Column A, but ALWAYS the 1st value, Not the Value associated to the Listbox3 value Corey.... "Tom Ogilvy" wrote in message ... If you want to walk backwards from the first row that is = Textbox1 in column C until you find a number in column A, then put that number in Label7 and quit looking: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long Dim bExit as Boolean On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell bExit = False If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = MyRow To 2 step - 1 If .Cells(i, 1).Value < "" Then If IsNumeric(.Cells(i, 1)) = True Then Label7 = .Cells(i, 1).Value bExit = True End If End If if bExit then exit for Next i End If End If if bExit then exit for Next myrow End With Application.ScreenUpdating = True End Sub -- Regards, Tom Ogilvy "Corey" wrote in message ... Got a Little Further: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = 2 To 22 If .Cells(myrow, 3).Offset(i, -2).Value < "" Then If IsNumeric(.Cells(myrow, 3).Offset(i, -2)) = True Then Label7 = .Cells(myrow, 3).Offset(i, -2).Value End If End If Next i End If End If Next End With Application.ScreenUpdating = True End Sub But the Value is in Column A but it is not the Correct Value? "Corey" wrote in message ... Rest of Message(sent accendently before completing Private Sub CommandButton2_Click() Label7 = ListBox3.Value Application.ScreenUpdating = True End Sub Corey.... |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom,
I will have a better look at your post, but in the meantime, Listbox3 is a list populated where the value (=) to the Textbox1 value is chosen from. ALSO, There CAN be (and is) sometimes the SAME value in Column C in different Column A ID's Ie. A C ID2 3 6 9 <== Same as in previous ID 1 ID2 C 10 4 9<= Same 8 2 4 Corey.... "Tom Ogilvy" wrote in message ... First, you should make a copy of your workbook and test any code I post in that copy so your original code is not disturbed. This should be your normal practice for any help you get from anyone. Frankly, your descriptions require quite a bit of interpretation and code provided could be off the mark (based on incorrect intepretations). This is what I understand you to say: Assuming the value in Textbox1 only occurs in a single cell in Column C and you want to find the value in column A of that row: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim rng as Range Dim rng1 as Range lastcell = Worksheets("InspectionData") _ .Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") set rng1 = .Range("C1:C" & lastrow) End with set rng = rng1.Find( _ what:=Textbox1.Value, _ After:=rng1(rng1.count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) if not rng is nothing then Label7.Caption = rng.offset(0,-2) else Label7.Caption = "Not Found" end if Application.ScreenUpdating = True End Sub or same assumptions about the value in C being unique, then If your data is like this A C ID1 3 6 9 1 and you search for 1 in C and want to put ID1 in Label 7 Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim rng as Range Dim rng1 as Range lastcell = Worksheets("InspectionData") _ .Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") set rng1 = .Range("C1:C" & lastrow) End with set rng = rng1.Find( _ what:=Textbox1.Value, _ After:=rng1(rng1.count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) if not rng is nothing then if not Isempty(rng.offset(0,-2)) then Label7.Caption = rng.offset(0,-2).Value else label7.Caption = rng.offset(0,-2).End(xlup).Value end if else Label7.Caption = "Not Found" end if Application.ScreenUpdating = True End Sub You spoke about listbox3, but it has never appeared in your code, so I have no idea how that figures in. -- regards, Tom Ogilvy "Corey" wrote in message ... Tom, The value placed in Textbox1 is a Minimum Value i need to find in the Column C. It represents various lengths contained in a roll Each roll has a unique Numerical ID (Column A) There can be up to 20 separate values in each Column A roll ID I have code that can find a value = Textbox1 value, But i need to identify the Column A Value that is Accociated to that minumum value(it will be in Column C I tried your code I get a Value that is in Column A, but ALWAYS the 1st value, Not the Value associated to the Listbox3 value Corey.... "Tom Ogilvy" wrote in message ... If you want to walk backwards from the first row that is = Textbox1 in column C until you find a number in column A, then put that number in Label7 and quit looking: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long Dim bExit as Boolean On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell bExit = False If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = MyRow To 2 step - 1 If .Cells(i, 1).Value < "" Then If IsNumeric(.Cells(i, 1)) = True Then Label7 = .Cells(i, 1).Value bExit = True End If End If if bExit then exit for Next i End If End If if bExit then exit for Next myrow End With Application.ScreenUpdating = True End Sub -- Regards, Tom Ogilvy "Corey" wrote in message ... Got a Little Further: Private Sub CommandButton2_Click() Application.ScreenUpdating = False Dim lastcell As Long Dim myrow As Long Dim i As Long On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell If .Cells(myrow, 3) < "" Then If .Cells(myrow, 3).Value = Val(TextBox1.Value) Then For i = 2 To 22 If .Cells(myrow, 3).Offset(i, -2).Value < "" Then If IsNumeric(.Cells(myrow, 3).Offset(i, -2)) = True Then Label7 = .Cells(myrow, 3).Offset(i, -2).Value End If End If Next i End If End If Next End With Application.ScreenUpdating = True End Sub But the Value is in Column A but it is not the Correct Value? "Corey" wrote in message ... Rest of Message(sent accendently before completing Private Sub CommandButton2_Click() Label7 = ListBox3.Value Application.ScreenUpdating = True End Sub Corey.... |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Not really sure if this will make things easier or more difficult to solve,
but the following code is what populates Listbox3. It When selected it may be easier to get Label7 to display the Column A value in this code(??) than by pressing a CommandButton? I do not know. Private Sub TextBox1_Change() Application.ScreenUpdating = False ListBox3.Clear If TextBox1.Value < "" Then Dim lastcell As Long Dim myrow As Long Dim i As Long On Error Resume Next lastcell = Worksheets("InspectionData").Cells(Rows.Count, "A").End(xlUp).Row With ActiveWorkbook.Worksheets("InspectionData") For myrow = 1 To lastcell If .Cells(myrow, 1) < "" Then If .Cells(myrow, 1).Offset(-1, 2).Value = ListBox1.Value Then If .Cells(myrow, 1).Offset(-1, 6).Value = ListBox2.Value Then For i = 2 To 22 If .Cells(myrow, 3).Offset(i, 0).Font.Strikethrough = False Then If Cells(myrow, 3).Offset(i, 0).Value < "" Then If IsNumeric(.Cells(myrow, 3).Offset(i, 0)) Then If .Cells(myrow, 3).Offset(i, 0).Value < "" And .Cells(myrow, 3).Offset(i, 0).Value = Val(TextBox1.Value) Then ListBox3.AddItem Cells(myrow, 3).Offset(i, 0) ListBox3.List(ListBox3.ListCount - 1, 1) = Cells(myrow, 3).Offset(i, 0).Address End If End If End If End If Next i End If End If End If Next End With End If Label8 = ListBox3.ListCount Application.ScreenUpdating = True End Sub Corey.... |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
divide column(x) by column(y) to give column(x/y) in excel? | New Users to Excel | |||
Referencing date column A & time column B to get info from column | Excel Discussion (Misc queries) | |||
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look | Excel Programming | |||
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look | Excel Discussion (Misc queries) | |||
How can i have all alike product codes in column A be matched with like cities in column B and then add the totals that are in column C | Excel Programming |