I have a sheet that has a range with numbers obtained from a scanner (scanner puts number in that range after using it) having information like serial number and date (from B9 to C20) and a cell (L2) which indicates the number of part. After printing this data with a button (print button with macros), a button for erasing the data from this range is used. What I would like to do is to have in the erase button a macro that copies the data from the range of cells and L2 to another sheet every time the button is pressed and create a database of this. Below is the sheet with the information.
Here's my current code:
Sub Test()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("Base de datos")
Set table_list_object = Sheets("Base de datos").ListObjects("table1")
Set table_object_row = table_list_object.ListRows.Add
last_row_with_data = the_sheet.Range("A65536").End(xlUp).Row
the_sheet.Range("A" & last_row_with_data) = ActiveSheet.Range("B9:B20")
the_sheet.Range("B" & last_row_with_data) = ActiveSheet.Range("C9:C20")
' the_sheet.Range("C" & last_row_with_data) = ActiveSheet.Range("L2")
' the_sheet.Range("D" & last_row_with_data) = ActiveSheet.Range("L3")
End Sub
You may need to amend this to fit your needs as im not exactly sure what your criteria is, but this should get you started! First, create a sheet called "Database." I'm assuming your copy range is static. If the range is not static, you can "un-comment" out the "RCount" portion of the code and amend to set a dynamic copy range.
Currently the code will copy your range (B9:M20) and paste it on a new sheet called "Database" at the last available row on Col A.
To clear out your table, I would create another macro below this (you can just record one) with title "Macro_Title." Before "End Sub"
Call Macro_Title
Macro
Public Sub Wow()
'Declare Variables
Dim wsOrigin As Worksheet
Dim wsDataBase As Worksheet
Set wsOrigin = Thisworkbook.Sheets("Base de datos")
Set wsDataBase = Thisworkbook.Sheets("Database")
Application.ScreenUpdating = False
'Copy/Special Paste Desired Data
Dim COPYME As Range
'Dim RCount As Integer
Dim RCount2 As Integer
'RCount = wsOrigin.Range("L" & wsOrigin.Rows.Count).End(xlUp).Row
RCount2 = wsDataBase.Range("A" & wsDataBase.Rows.Count).End(xlUp).Row
Set COPYME = wsOrigin.Range("B9:M20))
COPYME.Copy
wsDataBase.Range("A" & RCount2 + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.ScreenUpdating = True
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.