+ Reply to Thread
Results 1 to 17 of 17

#REF! Error when exporting Concatenated Cell VIA VBA code

  1. #1
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    #REF! Error when exporting Concatenated Cell VIA VBA code

    Hi All,

    I wrote a code that exports a cell to a .txt file. It is working properly with every cell, with the exception of the Concatenated cells. When exporting a concatenated cell, the text file reads #REF! only.

    I've debugged this error on a previous project but I cannot seem to figure this one out.

    Any help would be greatly appreciated.

    I'll attach two excel files - one where the macro exports the concatenated cell correctly and the other where I am getting the error.

    Thank you,

    Alec
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Which one is supposed to generate the error? Neither of those does for me.
    Rory

  3. #3
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    "Work in Progress" - try setting the cell to be copied to (2,27). I might have sent over the file testing a non-concatenated cell.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: #REF! Error when exporting Concatenated Cell VIA VBA code


    Hi,

    What is the VBA procedure name ?

  5. #5
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    I'm not sure how to upload a screen shot here, but this is what I'm referencing:

    Sub GenerateNote()
    'Update 20130913
    Dim wb As Workbook
    Dim saveFile As String
    Dim WorkRng As Range


    On Error Resume Next


    Set WorkRng = ActiveWorkbook.Sheets("NOTE").Cells(4, 24)
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set wb = Application.Workbooks.Add
    WorkRng.Copy
    wb.Worksheets(1).PasteSpecial
    saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
    wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
    wb.Close
    Application.CutCopyMode = xlCopy
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    That's not surprising as you are copying the formula. It refers to the cells three columns to the left, and if you copy that to column A, there are no cells three columns to the left.

    This seems like a lot of overhead to write one cell to a text file.

  7. #7
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Quote Originally Posted by Marc L View Post

    Hi,

    What is the VBA procedure name ?
    "Generate Note()"


    The code itself works. I've narrowed down the error to the cell/function of concatenate.

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    you could just use file IO:

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Quote Originally Posted by rorya View Post
    That's not surprising as you are copying the formula. It refers to the cells three columns to the left, and if you copy that to column A, there are no cells three columns to the left.

    This seems like a lot of overhead to write one cell to a text file.
    Yeah, it may seem like overkill, but it is a time saver in the long run.

    Which formula are you referring to? When I fill out the chart, Cell AA2 populates correctly.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Remove "On Error Resume Next", so that you will find
    Please Login or Register  to view this content.
    PasteSpecial is a method of Range object, not worksheet object.

  11. #11
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Quote Originally Posted by rorya View Post
    you could just use file IO:

    Please Login or Register  to view this content.
    That worked brilliantly!

  12. #12
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Thank you very much!

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Quote Originally Posted by jindon View Post
    PasteSpecial is a method of Range object, not worksheet object.
    It's actually a method of both.

  14. #14
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Rorya, can you help me understand where I went wrong? I'm new to VBA but would love to learn from my mistakes.

  15. #15
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    The formula in AA2 refers to cells in column X using relative addressing (i.e. X not $X). If you copy the formula somewhere else, the references will adjust so that they are always referring to cells three columns to the left. In this case, your code copies the formula to column A in a new sheet. There are no cells three columns to the left of A, so all the cell references get changed to #REF! errors. You could have just copied the value instead but, as I said, that seemed like overkill to put one cell in a text file.

  16. #16
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    Ahh I see, so if I'm understanding you correctly, I could have used absolute reference for the formula via $X, but that would have been overkill to re-type that for 91 cells.

    I'm going to delve into this more, but again, I really appreciate your help!

  17. #17
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: #REF! Error when exporting Concatenated Cell VIA VBA code

    That still wouldn't have helped you here because you copied the formula to a new sheet and on that sheet column X would be blank.

+ 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. Match a concatenated value in a concatenated list in a vba function
    By Rolly_Sefu in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-14-2021, 07:52 AM
  2. return multiple header cell values into one cell concatenated based on a cell value
    By anchuri_chaitanya in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-13-2016, 10:27 PM
  3. [SOLVED] Binary (concatenated from Decimal) to Hex Conversion Error
    By Talamon in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-19-2014, 12:19 PM
  4. [SOLVED] #REF error when deleting values from a row of concatenated cells.
    By mayeuxj in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-14-2013, 03:22 PM
  5. vba to Match concatenated values in concatenated columns
    By bjurick in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2012, 03:45 PM
  6. Replies: 0
    Last Post: 09-12-2007, 02:40 AM
  7. [SOLVED] Error exporting data
    By dida1981 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2005, 09:06 AM

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