+ Reply to Thread
Results 1 to 8 of 8

Exporting two Activecell Offset values to rows D and E of another sheet

  1. #1
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Question Exporting two Activecell Offset values to rows D and E of another sheet

    I'm hoping someone can tell me what I'm missing with this one. I tried to check with AI but it wants me to copy/paste and I'm getting a "Method not allowed" error.

    I'm trying to copy values on "Source Sheet", of two cells offset in the same row of my ActiveCell to the next available cells after rows 50 of the D and E columns of "DestinationSheet". This is what I have but it seems that no matter where I put the 2nd End if, it either wont run (if at the end) or it wont do the second transfer. I've tried doing with one LastRow reference and I'm getting the same result as the two. AI is telling me to do it with one LastRow reference but to copy and paste both, but I'm getting a "method not allowed" error that way. They seem to run a little faster when doing it destination=source so if that's possible I'd like to stick with that. I'm tempted to try to just have it run a second macro when it's done with column D, but I'd like to learn to do it the right way.


    Dim LastRow as Long
    Dim LastRow2 as Long

    LastRow =Sheets("Destinationsheet").Cells(Rows.Count, 4).End(xlUp).Row +1
    LastRow2 =Sheets("Destinationsheet").Cells(Rows.Count, 4).End(xlUp).Row +1

    If LastRow <= 50 Then
    LastRow = 51
    End If

    If Last Row2 <= 50 Then
    LastRow2 = 51
    End If

    Sheets("Destinationsheet").Range("D" & LastRow) = ActiveCell.Offset (0, 2).Value
    Sheets("Destinationsheet").Range("E" & LastRow) = ActiveCell.Offset (0, 8).Value

    End Sub
    Last edited by Anita Knapp; 05-05-2023 at 08:18 PM.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,543

    Re: Exporting two Activecell Offset values to rows D and E of another sheet

    Please Login or Register  to view this content.
    If Columns D and E in Destinationsheet are the same length, code can be made shorter.
    Experience trumps academics every day of the week and twice on Sunday.

  3. #3
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: Exporting two Activecell Offset values to rows D and E of another sheet

    Much closer but it's still a bit off. The first value is copying to the correct cell in column D but the second value is overwriting the previous value in column E so that there is now two items in column d and 1 item in column E.



    If I'm understanding the question correctly, they should be the same. The two columns wont have the same amount of characters but they'll always populate at the same time where the next available cell will be the same row for each.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,543

    Re: Exporting two Activecell Offset values to rows D and E of another sheet

    Not in my test file. Both values are added below the last used cells in Columns D and E.
    How many cells have data in Columns D and E?

    The way I understand this "next available cells after rows 50 of the D and E columns" is that if there is data less then 50 rows in these columns, it'll paste it in row 51 while if there is data past that row, it'll paste it into the next available empty cell.
    I could be totally wrong though.
    Last edited by jolivanes; 05-05-2023 at 06:53 PM.

  5. #5
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: Exporting two Activecell Offset values to rows D and E of another sheet

    Oh man, I messed that up, I'm sorry. I put consecutive columns but they're consecutive because they're merged. Would that mess it up? It's actually merged cells so it's D and G. I have another macro that puts the first entry in each of those columns and it works, but I didn't think about it making a difference with the next available.

    There is a macro that is run prior that puts one listing in Column D and one value in Column G. After that, there could be additions that would run from the macro I'm working on that builds off of those two. Hopefully that makes sense. Sorry for making it confusing!

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,543

    Re: Exporting two Activecell Offset values to rows D and E of another sheet

    https://edu.gcfglobal.org/en/excel-t...rging-cells/1/
    https://theexcelclub.com/stop-do-not...hy-with-fixes/
    https://www.perfectxl.com/excel-tool...t-merge-cells/
    The above articles give some insight into your problem.

    You can change any of the references to whatever is required as long as you are consistent and change everything that needs changing with it.
    If you want the 2nd line to work on a different column, like column G, change it to so
    Please Login or Register  to view this content.
    The preferred case would be for you to attach a representative workbook with personal, if present, stuff changed.
    There should be sufficient data to see what is going on and there should be a before and after.

  7. #7
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: Exporting two Activecell Offset values to rows D and E of another sheet

    I apologize if this posts twice, sometimes my posts don't go through here for some reason. You got it, I missed changing the (Rows.Count, 5). Its working correctly now, thank you!

    If you don't mind, I have one more question as I'm not sure if I'm understanding why the destination with (xlup) is listed twice. Is the first instance, IIf sh2.Cells(Rows.Count, 7).End(xlUp).Offset(1).Row)).Value only locating the last row, and second instance directing the text to the location?

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,543

    Re: Exporting two Activecell Offset values to rows D and E of another sheet

    That was my question as the last sentence in Post #2
    If the length of both columns is the same, the code can be changed and made more efficient to take that in consideration.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] ActiveCell.Offset with cell value to specify row offset
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-24-2021, 04:54 AM
  2. [SOLVED] IF condition copy paste Range(ActiveCell.Offset(,) in new sheet
    By incobart in forum Excel Programming / VBA / Macros
    Replies: 43
    Last Post: 07-13-2017, 06:39 AM
  3. Delete rows all at once instead of activecell.offset
    By mgblair in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2015, 02:43 PM
  4. [SOLVED] copy rows with activecell value and insert rows after activecell
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2014, 09:05 AM
  5. [SOLVED] ActiveCell.Offset excluding hidden rows
    By sleepa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2013, 09:37 AM
  6. activecell.offset
    By steelsoul in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2010, 09:23 AM
  7. ActiveCell.Offset via Dim
    By iturnrocks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2007, 11:13 PM

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