Posting to an adjacent cell

Subbie

New Member
Joined
May 11, 2019
Messages
32
as an old grey head approaching 70, I have decided to learn VBA. I have been grateful to this forum particularly in that Journey. Please forgive any error in protocols or procedures.
I have a Workbook which has a BankRec Sheet which has cheque numbers in AA:DY with headings (Week1 etc) in Row 2 and cheque data starting from Row 3 to 30 with column in between each week (Heading REC).
My task is to find the cheque number in Week column and then post 'Yes' in the adjacent cell in the rec column.
The UserForm4 has ComboBox1 with a dropdown list with Week1, Week2 etc to Week52 (Headings in AA:DY range Row 2)
There is a second ComboBox2 with a drop down List of the cheque numbers.
The Final ComboBox3 has the dropdown with 'Yes' and 'No'.

Everything works until the search and find portion of the code. I have tried various options and get errors of Object not found or compile issues.
The current code is:

Private Sub CommandButton1_Click()
With Application
.ScreenUpdating = False
.EnableEvents = False
End With


TargetSheet = "BankRec"
Worksheets(TargetSheet).Activate

Range("AA3").Select
Do
Cells.Find(What:="ComboBox2.Value", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate


ActiveSheet.Cells(ActiveCell + 1).Value = ComboBox3.Value

Loop


With Application
.ScreenUpdating = True
.EnableEvents = True
End With


MsgBox ("Data has been added successfully")
ComboBox1.Value = ""
ComboBox2.Value = ""
ComboBox3.Value = ""
Worksheets("Master").Activate
Worksheets("Master").Cells(1, 1).Select
End Sub
God any of your good people help me as after a few hours I am unable to solve the issue.
Any help would be gratefully appreciated.

Subbie
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Can any 2 or more weeks contain duplicate cheque numbers?
 
Upvote 0
Try:
Code:
Private Sub CommandButton1_Click()
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    Dim num As Range
    Set num = Sheets("BankRec").Cells.Find(ComboBox2.Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not num Is Nothing Then
        num.Offset(0, 1) = ComboBox3.Value
    Else
        MsgBox ("Cheque number not found.")
    End If
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    MsgBox ("Data has been added successfully.")
    ComboBox1.Value = ""
    ComboBox2.Value = ""
    ComboBox3.Value = ""
    With Sheets("Master")
        .Activate
        .Cells(1, 1).Select
    End With
End Sub
 
Upvote 0
Wow! Thanks mumps that works perfectly. Really appreciate you and your fast response...
Subbie
 
Upvote 0
Cells.Find(What:="ComboBox2.Value", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
You have your solution from 'mumps', but I thought you would like to know why your code failed. It is because of the quote marks you placed around "ComboBox2.Value". Anything you place within quote marks becomes nothing more than a collection of characters with no meaning attached to them to the VBA interpreter. So, as written, your code line was looking for the text "ComboBox2.Value" and not for the text selected within ComboBox2 itself. Remove the quote marks the Find method would have searched for the text you intended it to search for.
 
Upvote 0
You have your solution from 'mumps', but I thought you would like to know why your code failed. It is because of the quote marks you placed around "ComboBox2.Value". Anything you place within quote marks becomes nothing more than a collection of characters with no meaning attached to them to the VBA interpreter. So, as written, your code line was looking for the text "ComboBox2.Value" and not for the text selected within ComboBox2 itself. Remove the quote marks the Find method would have searched for the text you intended it to search for.
Thanks Rick
Great to have people who help and guide. both you and mumps have been excellent.
Subbie
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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