Consulting

Results 1 to 6 of 6

Thread: Problem with format and copy values

  1. #1

    Question Problem with format and copy values

    This code is to copy the values from sheet1 to sheet(bills) values after values and left between each values one row.
    But when I change the format ( the font or the size of font or bold?) of sheet("bills") it doesn?t work well .it copy the first values and left between them about 900 rows.
    [vba]
    Dim j As Integer
    j = Worksheets(lblagent.Caption).UsedRange.Rows.Count + 1 + Worksheets(lblagent.Caption).UsedRange.Row

    Sheets(1).Range("A24:A1000").Copy Worksheets(lblagent.Caption).Range("a" & j)
    [/vba]
    How to fix this problem ?

  2. #2
    VBAX Regular
    Joined
    Feb 2008
    Posts
    54
    Location
    Use this instead:

    Sheets(1).Range("A24:A1000").Copy Worksheets(lblagent.Caption).Range("a65536").End(xlUp).Offset(2)

  3. #3
    Thank you
    Why the property End(xlUp)?

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Mike
    Better to use
    [VBA]
    Sheets(1).Range("A24:A1000").Copy Worksheets(lblagent.Caption).Cells(Rows.Count, 1).End(xlUp).Offset(2)
    [/VBA]
    to ensure compatability with Excel2007
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Cells(Rows.Count, 1).End(xlUp) gives the same result as selecting the last cell in column A and pressing Control + Up Arrow. Offset(2) uses the cell 2 cells below the last used cell in the column.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6

Posting Permissions

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