+ Reply to Thread
Results 1 to 5 of 5

Thread: change macro code to read cell M20 intead of M21

  1. #1
    Registered User
    Join Date
    02-08-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    71

    change macro code to read cell M20 intead of M21

    Hi

    Please could someone advice what i need to change to make my code work.

    User enters "Date" in cell M19 and "Name" in cell M21.

    Below code works fine for cell M19 & M21 but i want to change the cell from M21 to M20 what part of code do i change to make it work.
        With Sheets("Main Menu") 'part of date & name
            LR = .Range("M" & Rows.Count).End(xlUp).Row
            For i = 19 To LR - 2 Step 4
                With .Range("M" & i)
                    .Copy Destination:=Sheets("Consumables Used From AM Rack").Range("A65535").End(xlUp).Offset(1, 0)
                    .ClearContents
                    With .Offset(2)
                        .Copy Destination:=Sheets("Consumables Used From AM Rack").Range("D65535").End(xlUp).Offset(1, 0)
                        .ClearContents
                    End With
                End With
            Next i
        End With
    Please can someone assist me.
    Last edited by coolhit; 07-23-2009 at 03:25 PM. Reason: Added Code Tags

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: change macro code to read cell M20 intead of M21

    Your code has a loop starting at M19/M21 and then moving to M23/M25 etc.

    Are you saying you want to go M19/M20, then M23/M24?

  3. #3
    Registered User
    Join Date
    02-08-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: change macro code to read cell M20 intead of M21

    Quote Originally Posted by StephenR View Post
    Your code has a loop starting at M19/M21 and then moving to M23/M25 etc.

    Are you saying you want to go M19/M20, then M23/M24?
    Currently the code read M19 & M21. I have change the design of sheet moveing the M21 to M20.

    These cell will stay static as user enter date (m19) and name (m20) cell.

    Loop should only do this two cell. Current codeing work but it looks at cell M21 which i want to change it to M20.

    Many thanks for assisting me.

  4. #4
    Valued Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Post Re: change macro code to read cell M20 intead of M21

    Currently the code read M19 & M21. I have change the design of sheet moveing the M21 to M20.

    These cell will stay static as user enter date (m19) and name (m20) cell.

    Loop should only do this two cell. Current codeing work but it looks at cell M21 which i want to change it to M20.
    So you ONLY want the macro to run on cells M19 and M20?
    I ask because that is not what the current macro is written to do...

    It is written to find the last row used in column M, and then operate on pairings such as:

    M19 and M21
    M23 and M25
    M27 and M29
    ...
    ...
    M(lastrow-2) and M(lastrow)
    So keep going until the second 'M' row is the last row of the spreadsheet.

    To confirm, are you saying you don't want it to do this, you just want it to do M19 for date, and M20 for name, and then stop?

    If so this is the modification necessary (removed lines in red, added code in blue):
        With Sheets("Main Menu") 'part of date & name
    '        LR = .Range("M" & Rows.Count).End(xlUp).Row
    '        For i = 19 To LR - 2 Step 4
    '            With .Range("M" & i)
                With .Range("M19")
                    .Copy Destination:=Sheets("Consumables Used From AM Rack").Range("A65535").End(xlUp).Offset(1, 0)
                    .ClearContents
    '                With .Offset(2)
                    With .Offset(1) ' Offset 1 row, (ie. from M19 to M20)
                        .Copy Destination:=Sheets("Consumables Used From AM Rack").Range("D65535").End(xlUp).Offset(1, 0)
                        .ClearContents
                    End With
                End With
    '        Next i
        End With
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: change macro code to read cell M20 intead of M21

    Change this line:
    With .Offset(2)
    to
    With .Offset(1)

+ 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.2.0