visual basic problem

B4L4KS

Board Regular
Joined
Mar 7, 2011
Messages
69
hello,

i have another problem with another worksteet, this involves customers being entered into a database and then moving down a line,

this is the code that i have

Sub adddetails()
'
' adddetails Macro
'
sourcerows = Array(8, 10, 12, 14, 16)
targetareas = Array("C", "D", "E", "F", "G")
targetrow = Sheets("Customers").Range("C" & Rows.Count).End(xlUp).Offset(1).Row
Sheets("Join Loyalty Scheme").Select
For i = LBound(sourcerows) To UBound(sourcerows)
Range("D" & sourcerows(i)).Resize(1, 1).Copy _
Destination:=Sheets("Customers").Range(targetareas(j) & targetrow)
Next
Application.CutCopyMode = False
End Sub

it doent work

anyhelp

kristian

note all the cells are correct just the visual basic is incorrect
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try adding the worksheet reference.

Something like this, assuming the source worksheet is 'Join Loyalty Sheet'.:)
Rich (BB code):
Worksheets("Join Loyalty Sheet").Range("D" & sourcerows(I)).Resize(1, 1).Copy _
Destination:=Sheets("Customers").Range(targetareas(j) & targetrow)
 
Upvote 0
hi it still doesnt work here is the code and where the data is going and coming from.

code
Sub adddetails()
'
' adddetails Macro
'

sourcerows = Array(8, 10, 12, 14, 16)
targetareas = Array("C", "D", "E", "F", "G")
targetrow = Sheets("Customers").Range("C" & Rows.Count).End(xlUp).Offset(1).Row
Worksheets("Join Loyalty Sheet").Range("D" & sourcerows(i)).Resize(1, 1).Copy _
Destination:=Sheets("Customers").Range(targetareas(i) & targetrow)

Next

Application.CutCopyMode = False
End Sub





many thanks

kristian
 
Upvote 0
This worked for me.
Code:
Sub adddetails()
 
    sourcerows = Array(8, 10, 12, 14, 16)
    
    targetareas = Array("C", "D", "E", "F", "G")
    
    targetrow = Sheets("Customers").Range("C" & Rows.Count).End(xlUp).Offset(1).Row
    
    For I = LBound(sourcerows) To UBound(sourcerows)
        Worksheets("Join Loyalty Sheet").Range("D" & sourcerows(I)).Copy Sheets("Customers").Range(targetareas(I) & targetrow)
    Next I
 
End Sub
You could do it like this too, which will either make things clearer or do the opposite and overcomplicate.:)
Code:
Option Explicit
 
Sub adddetails()
Dim wsSrc As Worksheet
Dim wsDst As Worksheet
Dim rngSrc As Range
Dim rngDst As Range
Dim targetrow As Long
Dim sourcerows
Dim targetareas
Dim I As Long
 
    sourcerows = Array(8, 10, 12, 14, 16)
 
    targetareas = Array("C", "D", "E", "F", "G")
 
    Set wsSrc = Worksheets("Join Loyalty Sheet")

    Set wsDst = Sheets("Customers")
 
    targetrow = wsDst.Range("C" & Rows.Count).End(xlUp).Offset(1).Row
 
    For I = LBound(sourcerows) To UBound(sourcerows)
        Set rngSrc = wsSrc.Range("D" & sourcerows(I))
        Set rngDst = wsDst.Range(targetareas(I) & targetrow)
        rngSrc.Copy rngDst
    Next I
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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