Weird Selection.Find problem

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Hi. I am trying to write a code where ComboBox2 value is found in another worksheet and then it is copied to a different sheet somewhere in between E125:E253 range(where the cell is empty).
The first problem i found is with just the Find part of the code where it gets the value if I use ActiveSheet.Columns("C:C").Select but refuse to work if I simply switch to Sheets("sheetsname").Columns("C:C").Select syntax, another problem is obviously gettign the empty cell from E125:E253 and then paste this Combox2 value into it
Here's the code that works with fiinding the value. the other part of functionality never worked for me.
VBA Code:
Private Sub add_Click()
Dim cell As Range
Dim lr As Long
Dim cena As String
Dim opis As String
Dim opis2 As String
Dim ilosc As String
Sheets("LISTA MATERIAŁÓW I OKUĆ").Activate
ActiveSheet.Columns("C:C").Select
Set cell = Selection.Find(what:=Me.ComboBox2.Value, after:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

If cell Is Nothing Then
    Exit Sub
Else
lr = Sheets("WYCENA").Range("E125:E253").Cells.Count
    Sheets("WYCENA").Range("E125:E253").Cells(lr + 1).Value = Me.ComboBox2.Value
    opis = cell.Offset(0, 1).Value
    cena = cell.Offset(0, 3).Value
    ilość = Me.TextBox3.Value
    opis2 = Me.TextBox2.Value
    'DEBUG PRINT'
    MsgBox opis
    MsgBox cena
    MsgBox ilość
    MsgBox opis2
    
End If
End Sub
Any idea how to make it work as intended?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
How about like
VBA Code:
Private Sub add_Click()
Dim cell As Range
Dim lr As Long
Dim cena As String
Dim opis As String
Dim opis2 As String
Dim ilosc As String
With Sheets("LISTA MATERIALÓW I OKUC")
Set cell = .Columns("C:C").Find(what:=Me.ComboBox2.Value, after:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
End With
If cell Is Nothing Then
    Exit Sub
Else
lr = Sheets("WYCENA").Range("E125:E253").SpecialCells(xlBlanks)(1).Row
    Sheets("WYCENA").Range("E" & lr).Value = Me.ComboBox2.Value
    opis = cell.Offset(0, 1).Value
    cena = cell.Offset(0, 3).Value
    ilosc = Me.TextBox3.Value
    opis2 = Me.TextBox2.Value
    'DEBUG PRINT'
    MsgBox opis
    MsgBox cena
    MsgBox ilosc
    MsgBox opis2

End If
End Sub
 
Upvote 0
Solution
1642685842347.png
1642685789733.png
 
Upvote 0

Forum statistics

Threads
1,214,854
Messages
6,121,941
Members
449,056
Latest member
denissimo

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