VBA & Macro for Command Button

Setal learner

New Member
Joined
Apr 28, 2019
Messages
5
Excel macro code for below requirement


I have a sheet "Daily Report" which contains 3 Pivot tables for 3 different staff.
the pivot table is populated based on the vlookup of the data from various other sheets


Engineer 1
Column C - Date of the activity
Column D - Name of the staff
Column E - Description of Activity
Column F - Total Hours
Column H - Remarks


What i require is as below


1. Command button for all 3 pivot tables separately but export the data to same new worksheet "Compiled Data"


2. After updating all the required details, the engineer will click submit (command button), the system must ask "Confirm to submit the data?
3. Upon clicking OK, it must pop-up a new box asking for selection of cell range that they wish to export
4. After selecting the range and clicking OK, the selected data must be export in "Compiled Data" sheet in the same workbook in the next empty row.
5. Similarly, when the next engineer clicks submit for his report, it must be added in the next empty row
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
They offer a paid for product build, unlike this forum where members will assist you in crafting parts of your project. No one is going to build an entire finished platform for you
 
Upvote 0
I already have a code but that is pasting my data in the adjacent columns and not rows

Code:
 --> This code is pasting in adjacent columns

Private Sub CommandButton1_Click()
Dim LC      As Long, _    rng     As Range    
Set rng = Sheets("Prices").Range("H5:J32")
LC = Sheets("Copied Prices").Cells(1, Columns.Count).End(xlToLeft).Column
If LC <> 1 Then LC = LC + 1rng.CopyWith Sheets("Copied Prices").Cells(1, LC)    .PasteSpecial xlPasteValues    .PasteSpecial xlPasteFormatsEnd With End Sub

2nd Option

Code:
 --> This code is pasting in another sheet but overwriting previous data

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim xSheet As Worksheet
    Set xSheet = ActiveSheet
        If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
            xSheet.Range("A1:C17 ").Copy
            xSheet.Range("J1:L17").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End If
 
    Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
Upvote 0
You are using activesheet for copy and paste in the 2nd code, with no activate or select to change the intended location. what would the sheet names be ?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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