Macro, 2 work books, no overwrite, loops, IF with conditions

Jbmcd

New Member
Joined
May 13, 2014
Messages
9
I’m hoping to get some help from a guru. I need to cut from one work sheet and paste to another with the click of a button without over writing data. I have code below that is working great but only partially doing this. I need to go much further, possibly using loops and if statements for conditions to be set?

I have two work books:
Tracker.xlsm / SalesTracker: consists of: products, product codes and account numbers. It is filled out daily with many different sales per day at different times of the day.
TrackerReports.xlsm: record keeping for all sales with product codes and account numbers for entire year.

This is what the end project will hopefully look like.
Tracker Reports:
http://jbmcd.com/UpSalesTracking/TrackerReports.xlsm or http://jbmcd.com/UpSalesTracking/TrackerReports.jpg

Tracker: http://jbmcd.com/UpSalesTracking/Tracker.xlsm or http://jbmcd.com/UpSalesTracking/Tracker.jpg

Tracker.xlsm / SalesTracker :


  1. Macro assigned to a button
  2. Cut/copy Column A and column B, rows 1 to 12 from Tracker.xlsm / SalesTracker
  3. Delete data in column A, not delete A3
  4. Paste all data from column A and B to TrackerReports.xlsm / sheet2
    (I have code for the above working properly but not for the below criteria).
TrackerReports.xlsm / sheet2:

  1. Paste by date of the columns.
TrackerReports.xlsm is laid out by:

  • 12 tabs/sheets for each month of the year.
Each of the 12 sheets consists of:
  • Laid out in columns
  • Row 1 has 31 merged cells with date (each day of the month).
  • Two columns under each date. One column for product code, second column for product sold.
(Several sales every day will be pasted from Tracker.xlsm / SalesTracker into TrackerReports.xlsm.)

  1. Pasting will be according to today’s date, data pasted from Tracker.xlsm / SalesTracker will be pasted in both columns under today’s date.
  2. Pasted data can not overwrite previously pasted data.

    This is the code I have so far and it working fine but not doing everything I need to do:

    Private Sub CommandButton1_Click()

    Dim LastRw As Long

    LastRw = Sheets("Sheet2").UsedRange.Rows.Count

    Sheets("Sheet2").Cells(LastRw + 1, "A").Value = Sheets("Sheet1").TextBoxes("TextBox 1").Text
    Sheets("Sheet2").Cells(LastRw + 1, "B").Value = Sheets("Sheet1").TextBoxes("TextBox 2").Text
    Sheets("Sheet2").Cells(LastRw + 1, "C").Value = TimeValue(Now)

    End Sub
    Sub CutPaste()
    '
    ' CutPaste Macro
    '

    '
    Range("A1:B12").Select
    Selection.Copy
    Windows("TrackerReports.xlsm").Activate
    Range("A2:B13").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Windows("Tracker.xlsm").Activate
    Range("A2").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("A4:A12").Select
    Selection.ClearContents
    Range("A2").Select
    End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,222,045
Messages
6,163,586
Members
451,846
Latest member
ajk99

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