Results 1 to 3 of 3

Thread: [RESOLVED] automate the writing of text value into rows and columns that can vary

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2012
    Posts
    90

    [RESOLVED] automate the writing of text value into rows and columns that can vary

    Hi

    I have a workbook that I create from a macro running in another workbook. The macro copies columns to the new (inactive, I guess) workbook into specific columns. So column "A" from the workbook can go into column "D" on the new workbook. I basically control which column by reading that as a number from a cell.

    The problem I have is that I want to fill in a text value in some other columns in the new workbook for each of the rows that are copied. So if I copied 100 rows to the new workbook into column D then I want column A to contain the text value 'Item' in rows 2 through to 102. The column is variable and the number of rows it needs to fill is also variable.

    Any idea how I can automate the filling of the text value into rows and columns that can vary?

    Many thanks
    paul
    Last edited by scoobster; Mar 19th, 2013 at 04:50 PM. Reason: solved

  2. #2
    Lively Member
    Join Date
    Jan 2009
    Posts
    93

    Re: how can I automate the writing of text value into rows and columns that can vary

    After you are done copying to new workbook, create a script to run that will loop thru starting at 2 and going to last row with data in it.

    Sample for you:

    'Code to get last row
    last_row = Range("D65536").End(xlUp).Row

    'For Loop, starts at Row 2, goes to last_row variable, set value of cell A"row" to Item
    For i = 2 To last_row

    Range("A" & i).Value = "Item"

    Next i

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2012
    Posts
    90

    Re: how can I automate the writing of text value into rows and columns that can vary

    Many thanks for the hint. Code is now working perfectly.

Posting Permissions

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



Click Here to Expand Forum to Full Width