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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

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