Using VBA to Copy Invoice Number

SilverLily

New Member
Joined
Jun 9, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi, this is my first time using VBA and what little I have done has been self taught using online information. I have created an invoice that once you click "enter" it moves all the invoice lines to the solddata worksheet and then clears itself. However, I cannot figure out how to get it to copy the invoice # on each of the lines it copies to the solddata sheet. It is a manual invoice number as we handwrite invoices. Any help would be greatly appreciated. What is in purple below works. What is in red is what I started to write to get the invoice number to copy with the invoice lines and realized I just have no idea how to do it.


Sub Copy_Paste_Below_Last_Cell()

'Find the last used row in both sheets and copy and paste data below existing data.

Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim CopyLastRow As Long
Dim DestLastRow As Long

'Set Variables for Copy and Destination

Set wsCopy = Workbooks("UU Inventory Tracker").Worksheets("Invoice")
Set wsDest = Workbooks("UU Inventory Tracker").Worksheets("SoldData")

'1. Find last used row in the copy range based on data in column C

CopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "C").End(xlUp).Row

'2. Find first blank row in destination range based on data in column C

DestLastRow = wsDest.Cells(wsDest.Rows.Count, "C").End(xlUp).Offset(1).Row


'3 Copy & Paste Data

wsCopy.Range("C14:G" & CopyLastRow).Copy _
wsDest.Range("C" & DestLastRow)

'4 Copy Invoice number & Invoice Date

If SoldData("E").Value >= 1 Then



'Reset Invoice (clear content after copied)

wsCopy.Range("C14:C29").ClearContents
wsCopy.Range("E14:E29").ClearContents
wsCopy.Range("G14:G29").ClearContents
wsCopy.Range("C6").ClearContents





End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
VBA Code:
If SoldData("E").Value >= 1 Then
SoldData("E") is not a valid range in VBA

If actually cell E1 of sheet SoldData, use:

VBA Code:
If WsDest.range("E1").value >=1 Then
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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