VBA code to copy and paste to specific worksheet/columns

K_Stevs1

New Member
Joined
Jan 27, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi I am have created a form in excel.

What I need help with is creating a code to copy and the paste the data into a specific worksheet and then the data into specific columns, on the next empty row.

Pictures of the excel attached.

In the form:
The person selects the type (which is one of the other 2 worksheets) - Cell C5
Then selects the Team (same on both tabs, anonymised for this purpose as (a, b, c ...)) - Cell F5
Then inputs the date of collection - Cell G5
Then in Cell C8 to C19 inputs the figure.

I want the data in to be copied into the columns in either Generic or Flying Start which ever is chosen in Cell C5,

I then need the data in Cells C8 to C19 to go into the column of the team selected in Cell F5.

I need the information in column A & B to go into the same column each time.

Is there a way to code this or am I better off trying a different method.

I really appropriate any help with this.

Many thanks

KS
 

Attachments

  • Screenshot 2022-01-27 131754.jpg
    Screenshot 2022-01-27 131754.jpg
    94.2 KB · Views: 7
  • Screenshot 2022-01-27 131909.jpg
    Screenshot 2022-01-27 131909.jpg
    32.4 KB · Views: 7

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
It is hard to work with pictures. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshot (not pictures) of your sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
It is hard to work with pictures. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshot (not pictures) of your sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
sorry not used this before, if it not correct I will try dropbox.

Test Form.xlsx
C
29
Form


Test Form.xlsx
ABCDEFGH
1DateCase Typeabcdef
2Apr-21U2549131115501050651918
3Apr-21E14941931047354
4Apr-21I1101347332742
5Apr-21LAC2219151188
6Apr-21CPR952826
7Apr-21CASPs10411428
8Apr-21E (4-5 YRS)1891924912
9Apr-21I (4-5 YRS)1707509
10Apr-21MARFs000300
11Apr-21MARACs000000
12Apr-21Referrals000000
13Apr-21Movements In0001600
14May-21U2059123614541052795978
Generic


Test Form.xlsx
ABCDEFGHI
1DateCase TypeabcdefH
2Apr-21U2581554872051633630
3Apr-21E6255135671881350
4Apr-21I15311868572590
5Apr-21LAC611364100
6Apr-21CPR53210850
7Apr-21CASPs154200720
8Apr-21E (4-5 YRS)180361828320
FS
 
Upvote 0
Test Form.xlsx
BCDEFGHIJ
1Test Data
2
3
4
5Case TypeTeamDate1/1/22
6
7Case TypeNumber of cases
8E
9I
10U
11LAC
12CPR
13CASPs
14E (4-5 YRS)
15I (4-5 YRS)
16MARFs
17MARACs
18Referrals
19Movements In
20
Form
Cells with Data Validation
CellAllowCriteria
C5ListGeneric, Flying Start
I5Datebetween 01/01/1900 and 01/12/5000
F5List='Team Lists'!$A$2:$A$9

sorry not used this before, if it not correct I will try dropbox.

Test Form.xlsx
C
29
Form


Test Form.xlsx
ABCDEFGH
1DateCase Typeabcdef
2Apr-21U2549131115501050651918
3Apr-21E14941931047354
4Apr-21I1101347332742
5Apr-21LAC2219151188
6Apr-21CPR952826
7Apr-21CASPs10411428
8Apr-21E (4-5 YRS)1891924912
9Apr-21I (4-5 YRS)1707509
10Apr-21MARFs000300
11Apr-21MARACs000000
12Apr-21Referrals000000
13Apr-21Movements In0001600
14May-21U2059123614541052795978
Generic


Test Form.xlsx
ABCDEFGHI
1DateCase TypeabcdefH
2Apr-21U2581554872051633630
3Apr-21E6255135671881350
4Apr-21I15311868572590
5Apr-21LAC611364100
6Apr-21CPR53210850
7Apr-21CASPs154200720
8Apr-21E (4-5 YRS)180361828320
FS
 
Upvote 0
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, team As Range, lRow As Long
    Set srcWS = Sheets("Form")
    lRow = Range("C" & Rows.Count).End(xlUp).Row
    Set team = Sheets(Range("C5").Value).Rows(1).Find(Range("F5").Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not team Is Nothing Then
        With Sheets(Range("C5").Value)
            .Range("A2").Resize(lRow - 7).Value = Range("H5")
            .Range("B2").Resize(lRow - 7).Value = Range("A8").Resize(lRow - 7).Value
            .Cells(2, team.Column).Resize(lRow - 7).Value = Range("C8").Resize(lRow - 7).Value
        End With
    Else
        MsgBox ("Team not found.")
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Than
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, team As Range, lRow As Long
    Set srcWS = Sheets("Form")
    lRow = Range("C" & Rows.Count).End(xlUp).Row
    Set team = Sheets(Range("C5").Value).Rows(1).Find(Range("F5").Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not team Is Nothing Then
        With Sheets(Range("C5").Value)
            .Range("A2").Resize(lRow - 7).Value = Range("H5")
            .Range("B2").Resize(lRow - 7).Value = Range("A8").Resize(lRow - 7).Value
            .Cells(2, team.Column).Resize(lRow - 7).Value = Range("C8").Resize(lRow - 7).Value
        End With
    Else
        MsgBox ("Team not found.")
    End If
    Application.ScreenUpdating = True
End Sub
Thank you I really appreciate your help, this works lovely, just one more question if you don't mind, how do I get the data to go to next empty row, of the data already submitted? instead of the top.
 
Upvote 0
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, team As Range, lRow As Long, lRow2 As Long
    Set srcWS = Sheets("Form")
    lRow = Range("C" & Rows.Count).End(xlUp).Row
    Set team = Sheets(Range("C5").Value).Rows(1).Find(Range("F5").Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not team Is Nothing Then
        With Sheets(Range("C5").Value)
            lRow2 = .Range("A" & .Rows.Count).End(xlUp).Row + 1
            .Range("A" & lRow2).Resize(lRow - 7).Value = Range("H5")
            .Range("B" & lRow2).Resize(lRow - 7).Value = Range("A8").Resize(lRow - 7).Value
            .Cells(lRow2, team.Column).Resize(lRow - 7).Value = Range("C8").Resize(lRow - 7).Value
        End With
    Else
        MsgBox ("Team not found.")
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Thank you so much, that works just as I needed.
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, team As Range, lRow As Long, lRow2 As Long
    Set srcWS = Sheets("Form")
    lRow = Range("C" & Rows.Count).End(xlUp).Row
    Set team = Sheets(Range("C5").Value).Rows(1).Find(Range("F5").Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not team Is Nothing Then
        With Sheets(Range("C5").Value)
            lRow2 = .Range("A" & .Rows.Count).End(xlUp).Row + 1
            .Range("A" & lRow2).Resize(lRow - 7).Value = Range("H5")
            .Range("B" & lRow2).Resize(lRow - 7).Value = Range("A8").Resize(lRow - 7).Value
            .Cells(lRow2, team.Column).Resize(lRow - 7).Value = Range("C8").Resize(lRow - 7).Value
        End With
    Else
        MsgBox ("Team not found.")
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,780
Messages
6,121,525
Members
449,037
Latest member
tmmotairi

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