Conditionally copying data from one sheet and adding as a new row to the end of Table1 in another sheet with a macro

mateinone

New Member
Joined
Feb 1, 2012
Messages
20
Office Version
  1. 2016
Platform
  1. Windows
Hi

I have 2 worksheets
InputData
Products

Table1 exists in "Products" sheet.

On InputData
I have a table that the user inputs data into, it does a check to ensure that no lines of data exist.
I also have a named range "data_chk" in cell A2 that contains TRUE or FALSE as per the logic below.

So what I am wanting to do is

The User enters data into a table
That data is first checked to see if any of the products they are trying to enter exists
At the end of each row there is a simple data validation to this end and this determines if data_chk is TRUE or FALSE

When I run the macro...

If data_chk equals TRUE,
A message box should appear and say
We cannot upload your data as you are entering a product that already exists.

If data_chk equals FALSE
I want to copy the data (let's just say there are two rows of data and they are in in cells B9:H10, in fact I will be using the following as it could be 2 or could be 10 rows

Range("B9:H9").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

So then with this data, I want to append it to the end of Table1 on the "Products Sheet".
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

kanadaaa

Active Member
Joined
Dec 29, 2019
Messages
345
Office Version
  1. 365
Platform
  1. Windows
Can you share sample images of the two worksheets so we can see more easily what you want to do with the macro?
 

MissingInAction

Board Regular
Joined
Sep 20, 2019
Messages
62
Office Version
  1. 365
Platform
  1. Windows
If I understand correctly, you want to copy and paste your data at the bottom of a table (first empty row). I used this code for a similar purpose:
VBA Code:
' Copy data entry and go to Data sheet
    Range("A5:L5").Select
    Selection.Copy
    Sheets("Data").Select
    Range("A2").Select
' Select last empty row
    Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
' Paste entry
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("AA1").Select
' Go to Input sheet and clear entry
    Sheets("Input").Select
    Range("C5").Select
    Selection.ClearContents
    Range("E5:L5").Select
    Range("L5").Activate
    Selection.ClearContents
    Range("C5").Select

You'll just need to edit the sheet names.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,666
Messages
5,637,662
Members
416,979
Latest member
juliegeorge792

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
Top