Using the find In VBA

Anonymous
2023-02-09T14:01:31+00:00

I am trying to write a macro that will deduct an item from my stock (which is housed in a different workbook) when I hit the complete button. My thoughts were to use the find function, activate the cell, and then subtract the quantity from the active cell. I am just starting with the macro, but I am running into an object error with my find.

Sub Deduct()

Dim C As String

'Deduct the Quantity from Stock

Workbooks.Open "C:\Users\furnd\Desktop\Test Deduct.xlsm"

With Workbooks("Test Deduct.xlsm").Sheets("Sheet1").Range("A1:A2000")

Set C = .Find(What:="A1").Value

End With

Workbooks("Test Deduct.xlsm").Activate

Sheets("Sheet1").Select

C.Offset(0, 1).Select

End Sub

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

47 answers

Sort by: Newest
  1. Anonymous
    2023-03-22T19:20:12+00:00

    Andreas,

    I was wondering if you could help me out on a coding question. I have been working on this project for a bit and thanks to the help that you and Jeovany have given me, I am getting close to having a working model. I am running into one issue. I need have code that opens another workbook. example below.

    Set Ledwb = Workbooks.Open _

    ("\TIMS-COMPUTER\Users\furnd\POS System\Ledger.xlsm")

    In a perfect world, no one should be in this workbook, but I know that could cause an error if someone is in it. Is there a way to write code that will throw and Error saying "Ledger.xlsm could not open" if the file is open elsewhere?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-03-10T17:05:17+00:00

    Jeovany,

    I am running into an issue when tryin to save the document as a pdf. I have been looking to see if I can find a fix for it, but I am having trouble. The invoice that you created will save as 1 page in a PDF, but the invoice that I created will print on 1 page, but when saving it as a pdf it will not save as 1 page. Below are some screenshots that show the issue.

    Here is the code I am using.

    Dim saveLocation As String

    Dealer = Range("D5")

    Invoice = Range("D2")

    saveLocation = "\TIMS-COMPUTER\Users\furnd\POS System\Invoices" & Dealer & "" & Invoice & ".pdf"

    'Save Active Sheet(s) as PDF

    ActiveSheet.ExportAsFixedFormat xlTypePDF, saveLocation

    Here are my margins.

    Here is the screen in excel that will print as 1 page.

    Here is how it looks when saving to PDF.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-03-07T19:02:55+00:00

    Actually, I just saw the teams meeting link from the post on the 5th

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-03-07T19:00:48+00:00

    Jeovany,

    I used the previous meeting link since there was not a new one posted. Please let me know if that is not what I should have done.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2023-03-06T18:38:50+00:00

    Jeovany

    Thank you for sending the files, I will take a look at them. I have already implement the creating a sold item list to my code, so I will be interested in comparing my approach to yours. I would be able to meet with on on Tuesday if that works. I should be good to meet at anytime. Please let me know what works best for you.

    That's Great.

    We can meet tomorrow Tuesday at 7 pm London time.

    Regards

    Was this answer helpful?

    0 comments No comments