making this automatic

everscern

Board Regular
Joined
Oct 10, 2006
Messages
56
Code:
Private Sub Button24_Click()
Dim txt As String, r As Range

   If WorksheetFunction.CountA(Range("b3:b9")) <> 7 Then Exit Sub
   Range("b10") = Empty
   txt = Range("b3").Text & "_" & Range("b4").Text & "_" & Range("b5").Text & "_" & Range("b6").Text & "_" & Range("b7").Text & "_" & Range("b8").Text & "_" & Range("b9").Text
   For Each r In Range("s3", Cells(3, Columns.Count).End(xlToLeft))
      If txt = r.Text & "_" & r.Offset(1).Text & "_" & r.Offset(2).Text & "_" & r.Offset(3).Text & "_" & r.Offset(4).Text & "_" & r.Offset(5).Text & "_" & r.Offset(6).Text Then
         Range("b10").Value = r.Offset(7).Value
         Exit For
      End If
   Next

End Sub

hi. how do i go about making this automatic, maybe thru looping? without having to depend on a button?

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
kkik.jpg


i deleted the previous code and added the code you created. Pls refer to the above.:)
 
Upvote 0
You can't do it...

You can not have same event driven subroutine in a module....

Delete all the code in Worksheet_Change event code and replace with this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
With Target.Cells(1,1)
   If Not Intersect(.Cells, Range("b3:b9")) Is Nothing Then
      Range("b24") = Empty     
      For i = 3 To 9 : txt = txt & Cells(i,"b").Value & "_" : Next
      For Each r In Range("s3",Cells(3,Columns.Count).End(xlToLeft))
         For i = 0 To 6 : txt2 = txt2 & r.Offset(i).Value & "_" : Next
         If txt = txt2 Then 
            Range("b10").Value = r.Offset(7).Value
            Exit For
         End If
      Next
   ElseIf Not Intersect(.Cells,Range("b17:b23")) Is Nothing Then
      Range("b24") = Empty
      For i = 17 To 23 : txt = txt & Cells(i,"b").Value & "_" : Next
      For Each r In Range("s17",Cells(17,Columns.Count).End(xlToLeft))
         For i = 0 To 6 : txt2 = txt2 & r.Offset(i).Value & "_" : Next
         If txt = txt2 Then
            Range("b24").VAlue = r.Offset(7).Value
            Exit For
         End If
      Next
   End If
End With
Application.EnableEvents = True
End Sub
 
Upvote 0
thanks for your patience. but now it shows : complie error; end without block if. it highlites this line: Private Sub Worksheet_Change(ByVal Target As Range)
 
Upvote 0
hi. it worked well. but the problem is i was not able to compare with column T. I was only able to compare with column S.

iii.jpg



thanks for your patience. we're getting there
 
Upvote 0
You shoud have posted this in the first place....
Delete all the code and replace with this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Long, y As Long, txt1 As String, txt2 As STring, r As Range
With Target.Cells(1,1)
    If .Column <> 2 Then Exit Sub
    If IsEmpty(.Offset(,-1)) Then Exit Sub
    With .CurrentRegion
       x = .Row + 1 : y = .Row + .Rows.Count - 1 : z = y - x
    End With
    If WorksheetFunction.CountA(Cells(x, "b").Resize(z)) <> z Then Exit Sub
    Application.EnableEvents = False
    Cells(y,"b").ClearContents 
    For i = x To y - 1 : txt = txt & Cells(i,"b").Value & "_" : Next
    With .Offset(,3).CurrentRegion
       For i = 2 To .Columns.Count
          For ii = x To y - 1 : txt2 = txt2 & Cells(ii, .Columns(i)).Value & "_" : Next
          If txt = txt2 Then
             Cells(y,"b").Value = Cells(y,.Columns(i)).Value
             Exit For
          End If
       Next
    End With
    Application.EnableEvents = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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