+ Reply to Thread
Results 1 to 10 of 10

pasting cell number of times

  1. #1
    Registered User
    Join Date
    02-24-2011
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    5

    pasting cell number of times

    I have picked up to write macro after a long time. So please bear with me here. I have following data

    Date Name
    2/22/11 A
    XXXXXX B
    XXXXXX C
    XXXXXX D

    Ignore XXXXXX read them as blank cells (added to keep formatting of post)

    The end state I want to get to is

    Date Name
    2/22/11 A
    2/22/11 B
    2/22/11 C
    2/22/11 D

    Now I have figured out how to count # of rows in 2nd column and put it in a variable "RecordCount" (Which will be 4 in this case) my question is how can I copy the data in cell A2 and paste it to next 3 cells below?
    Last edited by rockstart; 02-24-2011 at 03:43 PM.

  2. #2
    Registered User
    Join Date
    03-17-2009
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    10

    Re: pasting cell number of times

    is it always only three rows or will that vary? If it varies how is that determined?

  3. #3
    Registered User
    Join Date
    02-24-2011
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: pasting cell number of times

    Quote Originally Posted by texasalynn View Post
    is it always only three rows or will that vary? If it varies how is that determined?
    It varies and that is why I have found a way to do that count using the following function

    RecordCount = Application.WorksheetFunction.CountA(Range(Range("F8"), Range("F8").End(xlDown)))

    Now my RecordCount variable tells me how many rows I need to paste data.

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: pasting cell number of times

    hope that helps:
    Please Login or Register  to view this content.
    that pastes "test" into the range K1:K4

    Just FYI in order to select blank cells you can also use specialcells method (I do not know if its applicable in your case), see VB help for details
    Last edited by watersev; 02-24-2011 at 04:33 PM.

  5. #5
    Registered User
    Join Date
    02-24-2011
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: pasting cell number of times

    Quote Originally Posted by watersev View Post
    hope that helps:
    Please Login or Register  to view this content.
    that pastes "test" into the range K1:K4
    Thanks watersev. The issue I have is K1 is fixed but K4 is dynamic. I have that number stored in a variable so I need a dynamic function that can take my variable as parameter and then copy the data.

    is there a syntax for say
    [k1:k(variable_name)] = "test"
    Last edited by rockstart; 02-24-2011 at 04:36 PM.

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: pasting cell number of times

    is it all data you have or it's a sample with some more similar data going down?

  7. #7
    Registered User
    Join Date
    02-24-2011
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: pasting cell number of times

    Quote Originally Posted by watersev View Post
    is it all data you have or it's a sample with some more similar data going down?
    Its a sample of data I have. Basically I am consolidating data from different files into one spread sheet so every time I open a spread sheet I need to count the number of rows for NAME column and copy them over. Then the date field is only populated once in source sheet so when I copy it over I need to paste it against every name. Example one spread sheet has 4 names and othe other has 8. Next time I get another one I am not sure how many it can have it could range anywhere from 1 - 1000's

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: pasting cell number of times

    if it is:
    assuming Name is column B and data starts from second row and has no empty cells within table, it can be done this way without worksheet.function:
    Please Login or Register  to view this content.
    [a1] contains value we need to populate down the column A

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: pasting cell number of times

    if you can provide a sample workbook we could look at it together and find suitable solution for you

  10. #10
    Registered User
    Join Date
    02-24-2011
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: pasting cell number of times

    Quote Originally Posted by watersev View Post
    if it is:
    assuming Name is column B and data starts from second row and has no empty cells within table, it can be done this way without worksheet.function:
    Please Login or Register  to view this content.
    [a1] contains value we need to populate down the column A
    This is what worked for me. Its crude but did the trick

    For i = 2 To RecordCount + 1
    Range("A" & i).Select
    ActiveSheet.Paste
    Next i

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1