Help copying values

ColdGeorge

Active Member
Joined
Aug 21, 2012
Messages
412
Office Version
  1. 2016
Platform
  1. Windows
Hello all

What I’m trying to do is copy names from list in one sheet, on to another sheet where the word LECTOR is found, the thing is when I run code, last name of list is shown in all cells, I need first name of list in first cell, second name of list in second cell, and so on, any help would be appreciated.

ColdGeorge

Code:
Dim c As Range
Dim d As Range


For Each c In Sheets("Hoja1").Range("A2:A6")
    If c.Value <> "" Then
        c.Copy
        Sheets("Hoja2").Select
    End If
Next
        
    For Each d In Sheets("Hoja2").Range("A5:A13")
        If d.Value = "LECTOR" Then
            d.Offset(0, 1).PasteSpecial xlPasteValues
        End If
Next
    
Application.CutCopyMode = False
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
It looks like you need to next the second For loop in the first one. However, the end result will still be the last found non-blank. You might want to use Find instead. But, even then, if your number of names is more than LECTOR rows on the Hoja2, you will still get them overwritten.

Code:
  Dim c As Range
  Dim d As Range
  
  Dim sFirst As String
  
  
  For Each c In Worksheets("Hoja1").Range("A2:A6")
    If c.Value <> "" Then
      If Len(sFirst) = 0 Then
        Set d = Worksheets("Hoja2").Range("A5:A13").Find("LECTOR")
        sFirst = d.Address
      Else
        Set d = Worksheets("Hoja2").Range("A5:A13").FindNext(after:=d)
      End If
      
      d.Offset(0, 1).Value = c.Value
    End If
  Next c
 
Upvote 0
Hello iliace

Thanks for your help, it almost worked the way I want it, values from sheet1 are copied to the sheet2 starting in second cell and so on, last value is copied to first cell, what should I do to fix it?

ColdGeorge
 
Upvote 0
Hello iliace

Thanks for your help, it almost worked the way I want it, values from sheet1 are copied to the sheet2 starting in second cell and so on, last value is copied to first cell, what should I do to fix it?

ColdGeorge

This is where I'm stuck, I'm not entirely sure what you are trying to do. Can you post a before/after example?
 
Upvote 0
Hi iliace

This is a simple lectores schedule, there's a list of lectores and a date when they perform, list is in sheet1, dates are in sheet2, I just want to assign dates for each person in a orderly manner, first date first guy, second date second guy and so forth, what is the best way to perform this task?

ColdGeorge
 
Upvote 0
Can you post a before/after example? Your instance makes no sense. Please clarify.
 
Upvote 0
Hi, I am not sure I dit it right,

this is data in sheet1, column A1:A8, no spaces.
LECTOR
ANA
BERTHA
CARMEN
DEBORA
MARTHA
SUSANA
TANIA

<tbody>
</tbody>


This is sheet2, please note LECTOR is every other row, A1:A13, expected result is to have first name from list on top/first cell right next to LECTOR
LECTORTANIA
LECTORANA
LECTORBERTHA
LECTORCARMEN
LECTORDEBORA
LECTORMARTHA
LECTORSUSANA

<tbody>
</tbody>


Thanks for your patience, ColdGeorge
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,329
Members
451,637
Latest member
hvp2262

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