VBA for daily Trakker

Mumgirl

New Member
Joined
Jan 7, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi All,



Wish you all, Happy new year, Hope you are doing good !!!

I am new on MrExcel Forum, looking for VBA for few tasks

First Task – One-time activity

I am preparing the workforce daily tracking sheet for all our partners, we will send this file by mail to the partners.

Once they open this file, they will fill details in Starting B1 to B4, there is one filed “Pin to Transfer Data” A5, here they will put their desired pin – will explain this bit letter

Starting B7 to B26 they will write Technician Name, I want to have a macro to create (Add) sheets based on a list provided in B7:B26.

I want to prevent macro in duplicating sheet however user can add technician name to list and macro should be able to create sheet based on newly added name in range B7:B26

Once a sheet is created, I want to copy mater data format from a sheet called hidden – this data should come with formatting and all data validations

In home tab apart from A1:E30 Rest cells should be protected with Password ( Password=1234)

Daily Monitoring Format.xlsb
ABCDE
1RegionNorth
2BranchCalcutta
3ASC NameKaka Electronics
4GCS CodeG2345562
5Pin to Transfer Data
6T#Name
7T1
8T2
9T3
10T4
11T5
12T6
13T7
14T8
15T9
16T10
17T11
18T12
19T13
20T14
21T15
22T16
23T17
24T18
25T19
26T20
27
28
29
Home
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B6:B26Cell ValueduplicatestextNO
Cells with Data Validation
CellAllowCriteria
B1ListEast,North,South,West
B2ListAhmedabad,Bangalore,Bhubaneswar,Calcutta,Chandigarh,Chennai,Delhi,Ghaziabad,Guwahati,Hyderabad,Indore,Jaipur,Kochi,Lucknow,Mumbai,Pune


Second Task
Once Technician sheets are created, the user will fill the required details in each technician list on daily basis.

I want to have a macro button on each sheet by clicking this button macro to ask to enter “Pin to Transfer Data” using input box and match input data with cell B5 in Home tab, this is just to prevent accidental transfer of data

If the input value is matching with B5 copy date dynamically ( sheet may have less data – macro to check data Cell B2 to last filled row and copy ) and paste it in “ASC Summary” sheet in column E Date, if not matching show massage, “Please enter correct code”,

Macro to append data on each transfer.

The region, Branch, GCS code, Technician Name data is not available in Technician sheet, macro to take input of Region, Branch, GCS code from Home tab and technician name from sheet name from where data was transferred. Macro to match Row with data copied from sheet to avoid any mismatch.



I don’t know how difficult this activity but am looking forward for support from experts.

Thanks
MumGirl
 
Pretty sure i found the issue, there were 3 lines of code where i wasn't being explicit enough
VBA Code:
Sub addSheets()

For Each cell In ThisWorkbook.Sheets("Home").Range("B7:B26").Cells
    If cell <> "" Then 'if not at the end of the tech list then
        If DuplicateSheet(cell.Value) = False Then 'if tech name not a duplicate
            ThisWorkbook.Worksheets.Add 'Add a sheet
            ActiveSheet.Name = cell.Value 'Name sheet tech name
            ThisWorkbook.Sheets("Hidden").Cells.Copy ActiveSheet.Cells 'copy template from hiddel sheet to new sheet
            CreateButton ThisWorkbook.Sheets(cell.Value) 'create button on new sheet
        End If
    End If
Next cell

End Sub

Function DuplicateSheet(SheetName As String) As Boolean
    DuplicateSheet = False
    For Each sheet In ThisWorkbook.Sheets 'go through each sheet and make sure name doesn't already exist
        If sheet.Name = SheetName Then
            DuplicateSheet = True 'if duplicate then ignore sheet creation
            Exit For
        End If
    Next sheet
End Function

Function CreateButton(sht As Worksheet)
sht.Buttons.Add(1000, 20, 81, 36).Name = "New Button" ' Change these values to move and resize the buttons
With sht.Buttons("New Button")
    .Text = "Transfer Data" ' Text on the button
    .OnAction = "Transfer" ' sub called when button pressed
End With
End Function


Sub Transfer()
    'check pin with input
    Answer = InputBox("Please type the transfer pin from the home sheet here to continue", "Transfer the data now?")
    If Answer <> "" Then
        If Answer = ThisWorkbook.Sheets("Home").Range("B5") & "" Then
            'Passed all the tests
            If ThisWorkbook.Sheets("ASC Summary").Range("A1").Offset(1) = "" Then
                lastrow = ThisWorkbook.Sheets("ASC Summary").Range("A1").Offset(1).row
            Else
                lastrow = ThisWorkbook.Sheets("ASC Summary").Range("A1").End(xlDown).row + 1
            End If
            'Transfer data
            With ActiveSheet
                'add sheet data
                Dim RowCount As Integer
                RowCount = .Range("B1", "B" & .Range("B1").End(xlDown).row).Rows.Count - 1
                .Range("B2", "Q" & RowCount + 1).Copy ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 5)
                'add home data
                With ThisWorkbook.Sheets("Home")
                    .Range("B1:B2").Copy
                    'Application.Wait (Now + TimeValue("00:00:01"))
                    ThisWorkbook.Sheets("ASC Summary").Range(ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 1), ThisWorkbook.Sheets("ASC Summary").Cells(lastrow + RowCount - 1, 1)).PasteSpecial Transpose:=True
                    ThisWorkbook.Sheets("ASC Summary").Range(ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 3), ThisWorkbook.Sheets("ASC Summary").Cells(lastrow + RowCount - 1, 3)) = .Range("B4")
                End With
                ThisWorkbook.Sheets("ASC Summary").Range(ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 4), ThisWorkbook.Sheets("ASC Summary").Cells(lastrow + RowCount - 1, 4)) = .Name
                'Clear Sheet
                .Range("A2:Q100").ClearContents
            End With

        Else
            MsgBox "You have not entered the correct pin" & vbNewLine & "Please try again", vbCritical + vbOKOnly, "Something went wrong"
        End If
    End If
End Sub
Hi EFANYoutube,

Almost everything is fine only one last point, I have moved transfer button by increasing number to 1600 but still it is getting copied while transferring data to ASC summary.

Could you please share trick to avoid coping the same.

Thanks & Regards
This is just the transfer code so make sure you only overwrite the transfer sub
I added this line twice, one to turn it off then to turn it on again after the copy
VBA Code:
                Application.CopyObjectsWithCells = False

So just copy the code below


VBA Code:
Sub Transfer()
    'check pin with input
    Answer = InputBox("Please type the transfer pin from the home sheet here to continue", "Transfer the data now?")
    If Answer <> "" Then
        If Answer = ThisWorkbook.Sheets("Home").Range("B5") & "" Then
            'Passed all the tests
            If ThisWorkbook.Sheets("ASC Summary").Range("A1").Offset(1) = "" Then
                lastrow = ThisWorkbook.Sheets("ASC Summary").Range("A1").Offset(1).row
            Else
                lastrow = ThisWorkbook.Sheets("ASC Summary").Range("A1").End(xlDown).row + 1
            End If
            'Transfer data
            With ActiveSheet
                'add sheet data
                Dim RowCount As Integer
                RowCount = .Range("B1", "B" & .Range("B1").End(xlDown).row).Rows.Count - 1
                Application.CopyObjectsWithCells = False
                .Range("B2", "Q" & RowCount + 1).Copy ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 5)
                Application.CopyObjectsWithCells = True
                'add home data
                With ThisWorkbook.Sheets("Home")
                    .Range("B1:B2").Copy
                    'Application.Wait (Now + TimeValue("00:00:01"))
                    ThisWorkbook.Sheets("ASC Summary").Range(ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 1), ThisWorkbook.Sheets("ASC Summary").Cells(lastrow + RowCount - 1, 1)).PasteSpecial Transpose:=True
                    ThisWorkbook.Sheets("ASC Summary").Range(ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 3), ThisWorkbook.Sheets("ASC Summary").Cells(lastrow + RowCount - 1, 3)) = .Range("B4")
                End With
                ThisWorkbook.Sheets("ASC Summary").Range(ThisWorkbook.Sheets("ASC Summary").Cells(lastrow, 4), ThisWorkbook.Sheets("ASC Summary").Cells(lastrow + RowCount - 1, 4)) = .Name
                'Clear Sheet
                .Range("A2:Q100").ClearContents
            End With

        Else
            MsgBox "You have not entered the correct pin" & vbNewLine & "Please try again", vbCritical + vbOKOnly, "Something went wrong"
        End If
    End If
End Sub
Excellent now we hit the target, Code is working as per our requirement.

This is amazing, Thanks a lot for all your efforts and support, you are a magician – Really I mean it !!! ???
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,571
Messages
6,120,302
Members
448,954
Latest member
EmmeEnne1979

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