VBA to find next available cell and insert a value of one using Command Button

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
128
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Greetings everyone.
I am brand new to this but hungry to learn. I have searched for the answer to no avail.
I have 4 sheets in a workbook and sheet 2 is named InvoiceNumbers. Sheet 3 (MonthlyInvoices) is where I have a commandButton2 with the following code that I have scraped together....and not working.
When I click on the commandButton2 I want the following to happen:
go to sheet InvoiceNumbers and find the next empty cell in column F, and insert the value "1". Return to MonthlyInvoice and select cell C14 and throw up a message box to tell the user to enter the next customer number.
Your help will be greatly appreciated.
Private Sub CommandButton2_Click()
' Update Data


Sheets("InvoiceNumbers").Select
Column("F:F").Select
Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate


ActiveCell.FormulaR1C1 = "1"


Sheets("MonthlyInvoices").Select
Range("C14").Select
ActiveCell.FormulaR1C1 = "0"
Range("C14").Select
ActiveWorkbook.Save
CommandButton1.Enabled = True
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try:
Code:
Private Sub CommandButton2_Click()
    Application.ScreenUpdating = False
    Dim custNum As String
    Dim bottomF As Long
    bottomF = Sheets("InvoiceNumbers").Range("F" & Rows.Count).End(xlUp).Row
    Sheets("InvoiceNumbers").Range("F" & lastrow + 1) = "1"
    custNum = InputBox("Please enter a Customer Number.")
    If custNum = "" Then Exit Sub
    Sheets("MonthlyInvoices").Range("C14") = custNum
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,074
Messages
6,128,654
Members
449,462
Latest member
Chislobog

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