+ Reply to Thread
Results 1 to 6 of 6

How to advance one column to right?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241

    How to advance one column to right?

    Hi All,
    In my code I have chosen the last row in col A as cut it. Now I want to advance one column in the same row line and paste this value.

    Here is my code:

    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow + 0, 1).Select
    Application.CutCopyMode = False
    Selection.Cut
    i want to go one col to right in the same row and paste it. I am trying it for long but cannot get it to work.

    Appreciate your help.
    Thank you
    Syed Aziz

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Syed,

    You don't need to to use Cut/Copy/Paste to copy the contents of a cell into another cell. It looks like you have this code in the body of a with statement, so I didn't make any changes to the periods you have placed in the code.

    Example:
    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow, 1).Offset(0, 1).Value = .Cells(lRow, 1).Value

    The Offset adds the values to the cells's Row and Column numbers to create the new cell address. For the Row negative numbers more Left and positive move Right. For the Column negative numbers move Up and positive move Down.

    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241
    Thank you Leith. The fit in perfectly.
    Syed Aziz

  4. #4
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241

    Help Please

    Hi Leith/All
    Another Q.
    I am trying to put the calculated value in a message box for the user. It seems I am missing something here:

    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow + 1, 1).FormulaR1C1 = "=average(r2c:r[-1]c)"
    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow, 1).Offset(0, 1).Value = .Cells(lRow, 1).Value

    msgbox "Your Ave is " & lRow.value <-- here is the problem

    But it gives me an error saying it does not support~
    If I take out .value it give me row no. not the value.

    Appreciate your help.
    Thanks
    Syed

  5. #5
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241
    Hi Leith/All
    Another Q.
    I am trying to put the calculated value in a message box for the user. It seems I am missing something here:

    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow + 1, 1).FormulaR1C1 = "=average(r2c:r[-1]c)"
    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow, 1).Offset(0, 1).Value = .Cells(lRow, 1).Value

    msgbox "Your Ave is " & lRow.value <-- here is the problem

    But it gives me an error saying it does not support~
    If I take out .value it give me row no. not the value.

    Appreciate your help.
    Thanks
    Syed

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Syed,

    lRow is is a variable that holds the last row number. You get an error because you are trying to access it as a Range object. Add another variable to hold the average result. The message box can then refer to that variable to display the answer.

    Example:

    Dim Answer
    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow + 1, 1).FormulaR1C1 = "=average(r2c:r[-1]c)"
    Answer = .Cells(lRow + 1, 1).Value
    lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(lRow, 1).Offset(0, 1).Value = .Cells(lRow, 1).Value

    msgbox "Your Ave is " & Answer

    Sincerely,
    Leith Ross

+ 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