Hey guys
Im trying to copy some columns from one sheet and paste it onto another. I've come up with a code. Its supposed to copy items of 2 columns from the first worksheet which are "Profile" and "Email Address" and paste it onto the second worksheet on columns "ID"(Column 9 in Excel) and "Email Address"(Column 8 in Excel).
However it is only copying content of column "Profile" and pasting it twice on the second worksheet under "ID" and "Email Address" Can anyone see what I am doing wrong?
[/
Sub example()
Dim RoleWkb As Workbook, figWkb As Workbook, RoleWkst As Worksheet, figWkst As Worksheet
Set RoleWkb = Workbooks.Open("C:\Users\jjjj.xlsm")
Set figWkb = ThisWorkbook
Set RoleWkst = RoleWkb.Sheets("Profile")
Set figWkst = ConfigWkb.Worksheets("Information")
Dim cgroup As Range, cgroupstart As Range, cgroupend As Range
Dim ugroup As Range, ugroupstart As Range, ugroupend As Range
Dim name As Range
'***grabs procurement agents from workbook and copies
With figWkst
Set cgroup = .Columns(9).Find(What:="ID")
If Not cgroup Is Nothing Then
Set cgroupstart = cgroup.Offset(1)
Set cgroupend = Range(cgroupstart, cgroupstart.End(xlDown))
'if there are more than users
If WorksheetFunction.CountA(cgroupend) > 1 Then
cgroupend.Copy
'else (only one user)
Else: cgroupstart.Copy
End If
End If
End With
'pastes procurement agents to user role
With RoleWkst
Set ugroup = .Columns(1).Find(What:="User")
If Not ugroup Is Nothing Then
Set ugroupstart = ugroup.Offset(1, 0)
ugroupstart.PasteSpecial xlPasteValues
Set ugroupend = Range(ugroupstart, ugroupstart.End(xlDown))
If WorksheetFunction.CountA(ugroupend) > 2 Then
Else: Set ugroupend = Range(ugroupstart, ugroupstart.Offset(1))
End If
End If
End With
With figWkst
Set cgroup = .Columns(8).Find(What:="Email Address")
If Not cgroup Is Nothing Then
Set cgroupstart = cgroup.Offset(1, 1)
Set cgroupend = Range(cgroupstart, cgroupstart.End(xlDown))
If WorksheetFunction.CountA(cgroupend) > 1 Then
cgroupend.Copy
Else: cgroupstart.Copy
End If
End If
End With
'pastes cos USERID and e-mail
With RoleWkst
Set ugroup = .Columns(8).Find(What:="Email Address")
If Not ugroup Is Nothing Then
Set ugroupstart = ugroup.Offset(2, 2)
ugroupstart.PasteSpecial xlPasteValues
Set ugroupstart = ugroup.Offset(2, 4)
ugroupstart.PasteSpecial xlPasteValues
If WorksheetFunction.CountA(ugroupstart) > 1 Then
Set ugroupend = Range(ugroupstart, ugroupstart.End(xlDown))
Else: Set ugroupend = Range(ugroupstart, ugroupstart.Offset(1))
End If
End If
End With
End Sub
/]
Im trying to copy some columns from one sheet and paste it onto another. I've come up with a code. Its supposed to copy items of 2 columns from the first worksheet which are "Profile" and "Email Address" and paste it onto the second worksheet on columns "ID"(Column 9 in Excel) and "Email Address"(Column 8 in Excel).
However it is only copying content of column "Profile" and pasting it twice on the second worksheet under "ID" and "Email Address" Can anyone see what I am doing wrong?
[/
Sub example()
Dim RoleWkb As Workbook, figWkb As Workbook, RoleWkst As Worksheet, figWkst As Worksheet
Set RoleWkb = Workbooks.Open("C:\Users\jjjj.xlsm")
Set figWkb = ThisWorkbook
Set RoleWkst = RoleWkb.Sheets("Profile")
Set figWkst = ConfigWkb.Worksheets("Information")
Dim cgroup As Range, cgroupstart As Range, cgroupend As Range
Dim ugroup As Range, ugroupstart As Range, ugroupend As Range
Dim name As Range
'***grabs procurement agents from workbook and copies
With figWkst
Set cgroup = .Columns(9).Find(What:="ID")
If Not cgroup Is Nothing Then
Set cgroupstart = cgroup.Offset(1)
Set cgroupend = Range(cgroupstart, cgroupstart.End(xlDown))
'if there are more than users
If WorksheetFunction.CountA(cgroupend) > 1 Then
cgroupend.Copy
'else (only one user)
Else: cgroupstart.Copy
End If
End If
End With
'pastes procurement agents to user role
With RoleWkst
Set ugroup = .Columns(1).Find(What:="User")
If Not ugroup Is Nothing Then
Set ugroupstart = ugroup.Offset(1, 0)
ugroupstart.PasteSpecial xlPasteValues
Set ugroupend = Range(ugroupstart, ugroupstart.End(xlDown))
If WorksheetFunction.CountA(ugroupend) > 2 Then
Else: Set ugroupend = Range(ugroupstart, ugroupstart.Offset(1))
End If
End If
End With
With figWkst
Set cgroup = .Columns(8).Find(What:="Email Address")
If Not cgroup Is Nothing Then
Set cgroupstart = cgroup.Offset(1, 1)
Set cgroupend = Range(cgroupstart, cgroupstart.End(xlDown))
If WorksheetFunction.CountA(cgroupend) > 1 Then
cgroupend.Copy
Else: cgroupstart.Copy
End If
End If
End With
'pastes cos USERID and e-mail
With RoleWkst
Set ugroup = .Columns(8).Find(What:="Email Address")
If Not ugroup Is Nothing Then
Set ugroupstart = ugroup.Offset(2, 2)
ugroupstart.PasteSpecial xlPasteValues
Set ugroupstart = ugroup.Offset(2, 4)
ugroupstart.PasteSpecial xlPasteValues
If WorksheetFunction.CountA(ugroupstart) > 1 Then
Set ugroupend = Range(ugroupstart, ugroupstart.End(xlDown))
Else: Set ugroupend = Range(ugroupstart, ugroupstart.Offset(1))
End If
End If
End With
End Sub
/]