Set the number of rows for the FormulaArray

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys,
I want a few lines in the already existing code. Since I want to avoid, dragging the formula in cell F6 each time, I was hoping to write a code for the same.
With the help of a code, I want to replace the formula in cell F6 and get the same with a code added to the existing code. If there is data in column E and then I want the code to resize the cells in column F with column E. If the column E is blank I want the code to end and display MsgBox "All Ledgers available.". The formula to be inserted in F6 is ‘=VLOOKUP(E6,$A$6:$A$10000,1,0).
I am herewith sharing the link to my workbook.
formula array to resize cells.xlsm
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Replace formula with code.
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
As @Fluff mentioned, if you post your same question on a different forum, you have to also post the link to that other forum here.

That being said, I was extremely bored today so I did an overhaul to the code. I tried to move all of the adjustable variables to the top of the code to make it easier to edit the code later on.
Hopefully, I didn't break anything in the process.

I also tried to incorporate the changes that you asked for in the process.

Test the following out and let us know if any corrections need to be made:

VBA Code:
Option Explicit

Sub GenerateMasterXML()
'
'Working finally solved by Johnnyl 12:10 hrs 14.03.2022
'
    Application.ScreenUpdating = False                                                  ' Turn ScreenUpdating off
'
    Dim DictionaryRow                               As Long
    Dim FormulaNumber                               As Long
    Dim ImportMastersFormulaStartRow                As Long, List_of_LedgersColumnA_LastRow     As Long
    Dim ListOfLedgersFormulaStartRow                As Long
    Dim ParticularsMergedColumnCorrectionNumber     As Long
    Dim OriginalHeaderColumnNumber                  As Long, OriginalHeaderRow                  As Long, OriginalLastRow        As Long
    Dim ParticularsFooterLinesToExclude             As Long, ParticularsHeaderLinesToExclude    As Long
    Dim cell                                        As Range
    Dim AvoidText                                   As String
    Dim ImportMastersFormulaStartAddress            As String, MasterDataLedgersStartAddress    As String, VlookupStartAddress  As String
    Dim ImportMastersFormulaStartColumn             As String
    Dim ListOfLedgersFormulaColumn                  As String
    Dim ListOfLedgersLedgerColumn                   As String
    Dim MastersDataParticularsColumnLetter          As String
    Dim OriginalLastColumnLetter                    As String
    Dim ParticularsPasteListOfLedgersStartAddress   As String
    Dim TextToAvoid                                 As String
    Dim XML_FileName                                As String
    Dim DataDictionary                              As Variant
    Dim List_of_LedgersFormulasColumnArray          As Variant, OriginalParticularsDataArray    As Variant
    Dim wsImportMasters                             As Worksheet, wsListOfLedgers               As Worksheet
    Dim wsMasterData                                As Worksheet, wsOriginal                    As Worksheet
'
    Set wsImportMasters = Sheets("ImportMasters")
    Set wsListOfLedgers = Sheets("List of Ledgers")
       Set wsMasterData = Sheets("MasterData")
         Set wsOriginal = Sheets("Original")
'
    ImportMastersFormulaStartAddress = "A2"                                             ' <--- Adjust this if needed
    ImportMastersFormulaStartColumn = "A"                                               ' <--- Adjust this if needed
    ImportMastersFormulaStartRow = 2                                                    ' <--- Adjust this if needed
'
'---------------------------------------------------------------------------------------
'
    List_of_LedgersColumnA_LastRow = wsListOfLedgers.Range("A" & _
                wsListOfLedgers.Rows.Count).End(xlUp).Row                               ' Get last row used of column A in List of Ledgers sheet
'
'Or /\ /\ Comment out above line and uncomment \/ \/ to hard code the List_of_LedgersColumnA_LastRow
''    List_of_LedgersColumnA_LastRow = 10000                                              ' <--- Adjust this if needed
'
'---------------------------------------------------------------------------------------
'
    ListOfLedgersFormulaColumn = "F"                                                    ' <--- Adjust this if needed
    ListOfLedgersFormulaStartRow = 6                                                    ' <--- Adjust this if needed
    ListOfLedgersLedgerColumn = "E"                                                     ' <--- Adjust this if needed
    MasterDataLedgersStartAddress = "B2"                                                ' <--- Adjust this if needed
    MastersDataParticularsColumnLetter = "B"                                            ' <--- Adjust this if needed
    ParticularsFooterLinesToExclude = 3                                                 ' <--- Set this to # of rows to exclude from Bottom of Particulars
    ParticularsHeaderLinesToExclude = 1                                                 ' <--- Set this to # of rows to exclude from top of Particulars
    ParticularsMergedColumnCorrectionNumber = 1                                         ' <--- Set this to # of columns to correct for merged cells
    ParticularsPasteListOfLedgersStartAddress = "E6"                                    ' <--- Adjust this if needed
    TextToAvoid = "Opening Balance, (as per details), Closing Balance"                  ' <--- Adjust this if needed
    VlookupStartAddress = "$A$6"                                                        ' <--- Adjust this if needed
    XML_FileName = "C:\Users\" & Environ("username") & "\Desktop\Master.xml"            ' <--- Adjust this if needed
'
'---------------------------------------------------------------------------------------
'
    With wsOriginal
        OriginalLastColumnLetter = Split(Cells(1, (.Cells.Find("*", , xlFormulas, , _
                xlByColumns, xlPrevious).Column)).Address, "$")(1)                              '   Get last column letter used in the Original sheet
        OriginalLastRow = .Cells.Find("*", , xlFormulas, , xlByRows, _
                xlPrevious).Row - ParticularsFooterLinesToExclude                               '   Get correct last row of data on the Original sheet
'
        With .Range("A1:" & OriginalLastColumnLetter & OriginalLastRow)                         '   Look through the Original sheet for the header row
            Set cell = .Find("Particulars", LookIn:=xlValues)                                   '       Find the header called 'Particulars'
'
            If Not cell Is Nothing Then                                                         '       If 'Particulars' is found then ...
                OriginalHeaderRow = cell.Row + ParticularsHeaderLinesToExclude                  '           Save the row # into OriginalHeaderRow
                OriginalHeaderColumnNumber = cell.Column + ParticularsMergedColumnCorrectionNumber  '       Save corrected Column # into OriginalHeaderColumnNumber
'                                                                                               '               to correct for the merged B&C columns
            End If
        End With
'
        OriginalParticularsDataArray = .Range(.Cells(OriginalHeaderRow + 1, OriginalHeaderColumnNumber), _
                .Cells(OriginalLastRow, OriginalHeaderColumnNumber))                    ' Save Data to be pasted into 2D 1 Based OriginalParticularsDataArray
    End With
'
'---------------------------------------------------------------------------------------
'
    With wsListOfLedgers
        .Columns(ListOfLedgersLedgerColumn & ":" & ListOfLedgersFormulaColumn).ClearContents    '   Erase ListOfLedgersLedgerColumn &
'                                                                                               '       ListOfLedgersFormulaColumn in List of Ledgers sheet
        .Range(ParticularsPasteListOfLedgersStartAddress).Resize(UBound(OriginalParticularsDataArray, 1)) = _
                OriginalParticularsDataArray                                                    ' Display OriginalParticularsDataArray to List of Ledgers
'
        ReDim List_of_LedgersFormulasColumnArray(1 To UBound(OriginalParticularsDataArray, 1))  '   Set # of rows for the List_of_LedgersFormulasColumnArray
'
        For FormulaNumber = 1 To UBound(OriginalParticularsDataArray, 1)                        ' Loop to put formulas into List_of_LedgersFormulasColumnArray
            List_of_LedgersFormulasColumnArray(FormulaNumber) = "=VLOOKUP(E" & 5 + FormulaNumber & _
                    "," & VlookupStartAddress & ":$A$" & List_of_LedgersColumnA_LastRow & ",1,0)"   '   Save Formula into List_of_LedgersFormulasColumnArray
        Next                                                                                    ' Loop back
'
        .Range(ListOfLedgersFormulaColumn & ListOfLedgersFormulaStartRow).Resize(UBound(List_of_LedgersFormulasColumnArray, 1)) = _
                List_of_LedgersFormulasColumnArray                                              '   Display List_of_LedgersFormulasColumnArray ...
'                                                                                               '       to List of Ledgers sheet
        Application.Goto .Range(ParticularsPasteListOfLedgersStartAddress)                      '   Select ParticularsPasteListOfLedgersStartAddress on  List of Ledgers sheet
'
        DataDictionary = .Range(ParticularsPasteListOfLedgersStartAddress, _
                .Cells(Rows.Count, ListOfLedgersFormulaColumn).End(xlUp))                       '   Create DataDictionary
    End With
'
'---------------------------------------------------------------------------------------
'
'   solved by gravanoc 17:12 hrs 13.03.2022
    AvoidText = TextToAvoid                                                                     ' Text to avoid
'
    With CreateObject("Scripting.Dictionary")
        For DictionaryRow = 1 To UBound(DataDictionary)                                         '   Loop through each row of DataDictionary
            If Not .Exists(DataDictionary(DictionaryRow, 1)) And _
                    IsError(List_of_LedgersFormulasColumnArray(DictionaryRow)) Then             '       If unique value found &  ...
'                                                                                               '           Error found in column to the right then ...
                If InStr(1, AvoidText, DataDictionary(DictionaryRow, 1)) = 0 Then
                    .Add DataDictionary(DictionaryRow, 1), Array(DataDictionary(DictionaryRow, 2))  '               add unique value to DataDictionary
                End If
            End If
        Next                                                                                    '   Loop back
'
        wsMasterData.Range(MasterDataLedgersStartAddress, _
                wsMasterData.Range(MasterDataLedgersStartAddress).End(xlDown)).ClearContents    '   Erase column B data in MasterData sheet
'
        If .Count > 0 Then                                                                      '   Handle Error 13 when all match
            wsMasterData.Range(MasterDataLedgersStartAddress).Resize(.Count) = _
                    Application.Transpose(.keys)                                                '       Display unique values on wsMasterData
        End If
'
        If wsMasterData.Range(MasterDataLedgersStartAddress) = "" Then                          '   If all ledgers match then ...
            MsgBox "All Ledgers available."                                                     '       Display message to user
            Exit Sub                                                                            '       Exit sub
        End If
    End With
'
'---------------------------------------------------------------------------------------
'
    Application.Goto wsMasterData.Range("B1")                                                   ' Select B1 on MasterData sheet
'
    Dim LastColumnNumberInRow               As Long
    Dim LastRowInSheetImportMasters         As Long
    Dim LedgerCount                         As Long
    Dim xmlFile                             As Object
    Dim LastColumnLetterSheetImportMasters  As String
    Dim strData                             As String
    Dim strTempFile                         As String
'
    With wsImportMasters
        LastColumnLetterSheetImportMasters = Split(Cells(1, (.Cells.Find("*", , xlFormulas, _
                , xlByColumns, xlPrevious).Column)).Address, "$")(1)                            '   Get last column letter used in ImportMasters sheet
        LastRowInSheetImportMasters = .Cells.Find("*", , xlFormulas, , xlByRows, _
                xlPrevious).Row                                                                 '   Get last row used in ImportMasters sheet
'
        .Range(ImportMastersFormulaStartColumn & ImportMastersFormulaStartRow + 1 & ":" & _
                LastColumnLetterSheetImportMasters & LastRowInSheetImportMasters).ClearContents '   Erase all but one row of formulas on ImportMasters sheet
'
        LedgerCount = wsMasterData.Range(MasterDataLedgersStartAddress & ":" & _
                MastersDataParticularsColumnLetter & wsMasterData.Range(MastersDataParticularsColumnLetter & _
                Rows.Count).End(xlUp).Row).Rows.Count                                           '   Get count of ledgers
'
        If LedgerCount > 1 Then .Range(ImportMastersFormulaStartAddress & ":" & _
                LastColumnLetterSheetImportMasters & LedgerCount + 1).FillDown                  '   If LedgerCount > 1 Then Create range of formulas
'
        LastColumnNumberInRow = .Cells(ImportMastersFormulaStartRow, _
                .Columns.Count).End(xlToLeft).Column                                            '  Get last column # used in row ImportMastersFormulaStartRow
'
        .Range(ImportMastersFormulaStartAddress).Resize(LedgerCount, LastColumnNumberInRow).Copy    '   Copy ImportMasters Formula results
    End With
'
'---------------------------------------------------------------------------------------
'
    strData = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("Text")               ' Save contents into strData
    strTempFile = XML_FileName                                                                  ' Set File name to copy to
    CreateObject("Scripting.FileSystemObject").CreateTextFile(strTempFile, True).Write strData  ' Write the data to file
'
    MsgBox ("File saved on Desktop as Master.XML.")                                             ' Display message to user
'
    Application.ScreenUpdating = True                                                           ' Turn ScreenUpdating back on
End Sub
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Replace formula with code.
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Sorry fluff. I posted part of it, Forget to share the link as I dozed off. Will share the link, if I share, next time.
 
Upvote 0
As @Fluff mentioned, if you post your same question on a different forum, you have to also post the link to that other forum here.

That being said, I was extremely bored today so I did an overhaul to the code. I tried to move all of the adjustable variables to the top of the code to make it easier to edit the code later on.
Hopefully, I didn't break anything in the process.

I also tried to incorporate the changes that you asked for in the process.

Test the following out and let us know if any corrections need to be made:

VBA Code:
Option Explicit

Sub GenerateMasterXML()
'
'Working finally solved by Johnnyl 12:10 hrs 14.03.2022
'
    Application.ScreenUpdating = False                                                  ' Turn ScreenUpdating off
'
    Dim DictionaryRow                               As Long
    Dim FormulaNumber                               As Long
    Dim ImportMastersFormulaStartRow                As Long, List_of_LedgersColumnA_LastRow     As Long
    Dim ListOfLedgersFormulaStartRow                As Long
    Dim ParticularsMergedColumnCorrectionNumber     As Long
    Dim OriginalHeaderColumnNumber                  As Long, OriginalHeaderRow                  As Long, OriginalLastRow        As Long
    Dim ParticularsFooterLinesToExclude             As Long, ParticularsHeaderLinesToExclude    As Long
    Dim cell                                        As Range
    Dim AvoidText                                   As String
    Dim ImportMastersFormulaStartAddress            As String, MasterDataLedgersStartAddress    As String, VlookupStartAddress  As String
    Dim ImportMastersFormulaStartColumn             As String
    Dim ListOfLedgersFormulaColumn                  As String
    Dim ListOfLedgersLedgerColumn                   As String
    Dim MastersDataParticularsColumnLetter          As String
    Dim OriginalLastColumnLetter                    As String
    Dim ParticularsPasteListOfLedgersStartAddress   As String
    Dim TextToAvoid                                 As String
    Dim XML_FileName                                As String
    Dim DataDictionary                              As Variant
    Dim List_of_LedgersFormulasColumnArray          As Variant, OriginalParticularsDataArray    As Variant
    Dim wsImportMasters                             As Worksheet, wsListOfLedgers               As Worksheet
    Dim wsMasterData                                As Worksheet, wsOriginal                    As Worksheet
'
    Set wsImportMasters = Sheets("ImportMasters")
    Set wsListOfLedgers = Sheets("List of Ledgers")
       Set wsMasterData = Sheets("MasterData")
         Set wsOriginal = Sheets("Original")
'
    ImportMastersFormulaStartAddress = "A2"                                             ' <--- Adjust this if needed
    ImportMastersFormulaStartColumn = "A"                                               ' <--- Adjust this if needed
    ImportMastersFormulaStartRow = 2                                                    ' <--- Adjust this if needed
'
'---------------------------------------------------------------------------------------
'
    List_of_LedgersColumnA_LastRow = wsListOfLedgers.Range("A" & _
                wsListOfLedgers.Rows.Count).End(xlUp).Row                               ' Get last row used of column A in List of Ledgers sheet
'
'Or /\ /\ Comment out above line and uncomment \/ \/ to hard code the List_of_LedgersColumnA_LastRow
''    List_of_LedgersColumnA_LastRow = 10000                                              ' <--- Adjust this if needed
'
'---------------------------------------------------------------------------------------
'
    ListOfLedgersFormulaColumn = "F"                                                    ' <--- Adjust this if needed
    ListOfLedgersFormulaStartRow = 6                                                    ' <--- Adjust this if needed
    ListOfLedgersLedgerColumn = "E"                                                     ' <--- Adjust this if needed
    MasterDataLedgersStartAddress = "B2"                                                ' <--- Adjust this if needed
    MastersDataParticularsColumnLetter = "B"                                            ' <--- Adjust this if needed
    ParticularsFooterLinesToExclude = 3                                                 ' <--- Set this to # of rows to exclude from Bottom of Particulars
    ParticularsHeaderLinesToExclude = 1                                                 ' <--- Set this to # of rows to exclude from top of Particulars
    ParticularsMergedColumnCorrectionNumber = 1                                         ' <--- Set this to # of columns to correct for merged cells
    ParticularsPasteListOfLedgersStartAddress = "E6"                                    ' <--- Adjust this if needed
    TextToAvoid = "Opening Balance, (as per details), Closing Balance"                  ' <--- Adjust this if needed
    VlookupStartAddress = "$A$6"                                                        ' <--- Adjust this if needed
    XML_FileName = "C:\Users\" & Environ("username") & "\Desktop\Master.xml"            ' <--- Adjust this if needed
'
'---------------------------------------------------------------------------------------
'
    With wsOriginal
        OriginalLastColumnLetter = Split(Cells(1, (.Cells.Find("*", , xlFormulas, , _
                xlByColumns, xlPrevious).Column)).Address, "$")(1)                              '   Get last column letter used in the Original sheet
        OriginalLastRow = .Cells.Find("*", , xlFormulas, , xlByRows, _
                xlPrevious).Row - ParticularsFooterLinesToExclude                               '   Get correct last row of data on the Original sheet
'
        With .Range("A1:" & OriginalLastColumnLetter & OriginalLastRow)                         '   Look through the Original sheet for the header row
            Set cell = .Find("Particulars", LookIn:=xlValues)                                   '       Find the header called 'Particulars'
'
            If Not cell Is Nothing Then                                                         '       If 'Particulars' is found then ...
                OriginalHeaderRow = cell.Row + ParticularsHeaderLinesToExclude                  '           Save the row # into OriginalHeaderRow
                OriginalHeaderColumnNumber = cell.Column + ParticularsMergedColumnCorrectionNumber  '       Save corrected Column # into OriginalHeaderColumnNumber
'                                                                                               '               to correct for the merged B&C columns
            End If
        End With
'
        OriginalParticularsDataArray = .Range(.Cells(OriginalHeaderRow + 1, OriginalHeaderColumnNumber), _
                .Cells(OriginalLastRow, OriginalHeaderColumnNumber))                    ' Save Data to be pasted into 2D 1 Based OriginalParticularsDataArray
    End With
'
'---------------------------------------------------------------------------------------
'
    With wsListOfLedgers
        .Columns(ListOfLedgersLedgerColumn & ":" & ListOfLedgersFormulaColumn).ClearContents    '   Erase ListOfLedgersLedgerColumn &
'                                                                                               '       ListOfLedgersFormulaColumn in List of Ledgers sheet
        .Range(ParticularsPasteListOfLedgersStartAddress).Resize(UBound(OriginalParticularsDataArray, 1)) = _
                OriginalParticularsDataArray                                                    ' Display OriginalParticularsDataArray to List of Ledgers
'
        ReDim List_of_LedgersFormulasColumnArray(1 To UBound(OriginalParticularsDataArray, 1))  '   Set # of rows for the List_of_LedgersFormulasColumnArray
'
        For FormulaNumber = 1 To UBound(OriginalParticularsDataArray, 1)                        ' Loop to put formulas into List_of_LedgersFormulasColumnArray
            List_of_LedgersFormulasColumnArray(FormulaNumber) = "=VLOOKUP(E" & 5 + FormulaNumber & _
                    "," & VlookupStartAddress & ":$A$" & List_of_LedgersColumnA_LastRow & ",1,0)"   '   Save Formula into List_of_LedgersFormulasColumnArray
        Next                                                                                    ' Loop back
'
        .Range(ListOfLedgersFormulaColumn & ListOfLedgersFormulaStartRow).Resize(UBound(List_of_LedgersFormulasColumnArray, 1)) = _
                List_of_LedgersFormulasColumnArray                                              '   Display List_of_LedgersFormulasColumnArray ...
'                                                                                               '       to List of Ledgers sheet
        Application.Goto .Range(ParticularsPasteListOfLedgersStartAddress)                      '   Select ParticularsPasteListOfLedgersStartAddress on  List of Ledgers sheet
'
        DataDictionary = .Range(ParticularsPasteListOfLedgersStartAddress, _
                .Cells(Rows.Count, ListOfLedgersFormulaColumn).End(xlUp))                       '   Create DataDictionary
    End With
'
'---------------------------------------------------------------------------------------
'
'   solved by gravanoc 17:12 hrs 13.03.2022
    AvoidText = TextToAvoid                                                                     ' Text to avoid
'
    With CreateObject("Scripting.Dictionary")
        For DictionaryRow = 1 To UBound(DataDictionary)                                         '   Loop through each row of DataDictionary
            If Not .Exists(DataDictionary(DictionaryRow, 1)) And _
                    IsError(List_of_LedgersFormulasColumnArray(DictionaryRow)) Then             '       If unique value found &  ...
'                                                                                               '           Error found in column to the right then ...
                If InStr(1, AvoidText, DataDictionary(DictionaryRow, 1)) = 0 Then
                    .Add DataDictionary(DictionaryRow, 1), Array(DataDictionary(DictionaryRow, 2))  '               add unique value to DataDictionary
                End If
            End If
        Next                                                                                    '   Loop back
'
        wsMasterData.Range(MasterDataLedgersStartAddress, _
                wsMasterData.Range(MasterDataLedgersStartAddress).End(xlDown)).ClearContents    '   Erase column B data in MasterData sheet
'
        If .Count > 0 Then                                                                      '   Handle Error 13 when all match
            wsMasterData.Range(MasterDataLedgersStartAddress).Resize(.Count) = _
                    Application.Transpose(.keys)                                                '       Display unique values on wsMasterData
        End If
'
        If wsMasterData.Range(MasterDataLedgersStartAddress) = "" Then                          '   If all ledgers match then ...
            MsgBox "All Ledgers available."                                                     '       Display message to user
            Exit Sub                                                                            '       Exit sub
        End If
    End With
'
'---------------------------------------------------------------------------------------
'
    Application.Goto wsMasterData.Range("B1")                                                   ' Select B1 on MasterData sheet
'
    Dim LastColumnNumberInRow               As Long
    Dim LastRowInSheetImportMasters         As Long
    Dim LedgerCount                         As Long
    Dim xmlFile                             As Object
    Dim LastColumnLetterSheetImportMasters  As String
    Dim strData                             As String
    Dim strTempFile                         As String
'
    With wsImportMasters
        LastColumnLetterSheetImportMasters = Split(Cells(1, (.Cells.Find("*", , xlFormulas, _
                , xlByColumns, xlPrevious).Column)).Address, "$")(1)                            '   Get last column letter used in ImportMasters sheet
        LastRowInSheetImportMasters = .Cells.Find("*", , xlFormulas, , xlByRows, _
                xlPrevious).Row                                                                 '   Get last row used in ImportMasters sheet
'
        .Range(ImportMastersFormulaStartColumn & ImportMastersFormulaStartRow + 1 & ":" & _
                LastColumnLetterSheetImportMasters & LastRowInSheetImportMasters).ClearContents '   Erase all but one row of formulas on ImportMasters sheet
'
        LedgerCount = wsMasterData.Range(MasterDataLedgersStartAddress & ":" & _
                MastersDataParticularsColumnLetter & wsMasterData.Range(MastersDataParticularsColumnLetter & _
                Rows.Count).End(xlUp).Row).Rows.Count                                           '   Get count of ledgers
'
        If LedgerCount > 1 Then .Range(ImportMastersFormulaStartAddress & ":" & _
                LastColumnLetterSheetImportMasters & LedgerCount + 1).FillDown                  '   If LedgerCount > 1 Then Create range of formulas
'
        LastColumnNumberInRow = .Cells(ImportMastersFormulaStartRow, _
                .Columns.Count).End(xlToLeft).Column                                            '  Get last column # used in row ImportMastersFormulaStartRow
'
        .Range(ImportMastersFormulaStartAddress).Resize(LedgerCount, LastColumnNumberInRow).Copy    '   Copy ImportMasters Formula results
    End With
'
'---------------------------------------------------------------------------------------
'
    strData = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("Text")               ' Save contents into strData
    strTempFile = XML_FileName                                                                  ' Set File name to copy to
    CreateObject("Scripting.FileSystemObject").CreateTextFile(strTempFile, True).Write strData  ' Write the data to file
'
    MsgBox ("File saved on Desktop as Master.XML.")                                             ' Display message to user
'
    Application.ScreenUpdating = True                                                           ' Turn ScreenUpdating back on
End Sub
JohnnyL. The code stops running at All ledgers Available, even if there are NA ledgers.
 
Upvote 0
The code I submitted works fine. Only thing is I have to drag the formula till the end in column F, manually.
 
Upvote 0
When I tested a file which had 300 NA ledgers I noticed the problem.
 
Upvote 0
Rich (BB code):
wsMasterData.Range(MasterDataLedgersStartAddress, _
                wsMasterData.Range(MasterDataLedgersStartAddress).End(xlDown)).ClearContents    '   Erase column B data in MasterData sheet
'
Is this line erasing the data.? should it be in the beginning of the code.? Not sure..
 
Upvote 0
How much you have worked on this code. Code, presentation, explanation to each line, Just mind blowing.
 
Upvote 0

Forum statistics

Threads
1,215,603
Messages
6,125,786
Members
449,259
Latest member
rehanahmadawan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top