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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
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)
 

B4L4KS

Board Regular
Joined
Mar 7, 2011
Messages
69
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,031
Messages
5,856,937
Members
431,841
Latest member
jaybeem

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