Adding visual basic to a macro

B4L4KS

Board Regular
Joined
Mar 7, 2011
Messages
69
hello

i need to create a macro that adds a new customer and their details to a customer database, first name, last name, address ect.

this will cut data from my first page and insert it into another, this will also have to include a function of adding a new line below for then next new customers details.

this is the code i have already below.

Code:
Sub adddetails()
'
' adddetails Macro
'

'
    Range("Q12:R12").Select
    Selection.Copy
    Sheets("Customer Details").Select
    Range("G22:H22").Select
    ActiveSheet.Paste
    Sheets("Home Page").Select
    Range("Q13:R13").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Customer Details").Select
    Range("I22:J22").Select
    ActiveSheet.Paste
    Sheets("Home Page").Select
    Range("Q17:R17").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Customer Details").Select
    Range("M22:N22").Select
    ActiveSheet.Paste
    Sheets("Home Page").Select
    Range("Q18:R18").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Customer Details").Select
    Range("O22:P22").Select
    ActiveSheet.Paste
    Sheets("Home Page").Select
    Range("Q19:R19").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Customer Details").Select
    Range("Q22:R22").Select
    ActiveSheet.Paste
    Sheets("Home Page").Select
    Range("Q20:R20").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Customer Details").Select
    Range("S22:T22").Select
    ActiveSheet.Paste
End Sub

i am not very good at macros as you can see but i really need help

thanks in advance

Kristian
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

SteveO59L

Well-known Member
Joined
Apr 21, 2004
Messages
7,896
I assume that the referenced cells in your sheet "Home Page" will be constant, and the cells in sheet "Customer Details", will need to increment by one as you add a new customer.
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,547
This is one way:
Code:
Sub adddetails()
'
' adddetails Macro
'

sourcerows = Array(12, 13, 17, 18, 19, 20)
targetareas = Array("G", "I", "M", "O", "Q", "S")
targetrow = Sheets("Customer Details").Range("G" & Rows.Count).End(xlUp).Offset(1).Row
Sheets("Home Page").Select
For i = LBound(sourcerows) To UBound(sourcerows)
    Range("Q" & sourcerows(i)).Resize(1, 2).Copy _
        Destination:=Sheets("Customer Details").Range(targetareas(i) & targetrow)
Next
Application.CutCopyMode = False
End Sub
 

Forum statistics

Threads
1,141,734
Messages
5,708,168
Members
421,549
Latest member
Dtcfire

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