Need to replace formulas with code

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys,

With the help of a code, I have this result data in sheet B from column A to G in a vertical order. Columns K:BD contain formulas to sort the data horizontally as shown in the image. As the formulas are too lengthy and in thousands of cells, the code takes a lot of time in calculating threads. To reduce the time taken for the macro to get the result, I was hoping somebody willing to help me to write a code to get the result from column A to G to Columns K:BD.
Shared Test.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBD
1COPY THE RESULT AND PASTE TO NEW SHEET WITH PASTE SPECIAL - VALUES
2DateVch TypeVch No.NarrationParticularsDebit NegativeCredit PositiveTotal AmtDateVch TypeVch No.NarrationLedger 1AmtLedger 2AmtLedger 3AmtLedger 4AmtLedger 5AmtLedger 6AmtLedger 7AmtLedger 8AmtLedger 9AmtLedger 10AmtLedger 11AmtLedger 12AmtLedger 13AmtLedger 14AmtLedger 15AmtLedger 16AmtLedger 17AmtLedger 18AmtLedger 19AmtLedger 20AmtLedger 21Amt
302-08-2021Receipt1026ICICI-16380.00-1638002-08-2021Receipt1026ICICI-16380January4823February11720March-163
402-08-2021Receipt1026January4823.00482303-08-2021Receipt1027ICICI-2000January1000January1000
502-08-2021Receipt1026February11720.001172003-08-2021Receipt1028ICICI-2770January2800February-30
602-08-2021Receipt1026March-163.00-16304-08-2021Payment1029ICICI1062Sunday-944Monday-118
703-08-2021Receipt1027ICICI-2000.00-200004-08-2021Receipt1030ICICI-1704Monday984Tuesday720
803-08-2021Receipt1027January1000.00100004-08-2021Payment1031ICICI94572Monday-94612Tuesday40
903-08-2021Receipt1027January1000.00100000
1003-08-2021Receipt1028ICICI-2770.00-27700
1103-08-2021Receipt1028January2800.002800
1203-08-2021Receipt1028February-30.00-30
1304-08-2021Payment1029ICICI1062.001062
1404-08-2021Payment1029Sunday-944.00-944
1504-08-2021Payment1029Monday-118.00-118
1604-08-2021Receipt1030ICICI-1704.00-1704
1704-08-2021Receipt1030Monday984.00984
1804-08-2021Receipt1030Tuesday720.00720
1904-08-2021Payment1031ICICI94572.0094572
2004-08-2021Payment1031Monday-94612.00-94612
2104-08-2021Payment1031Tuesday40.0040
B
 
Rich (BB code):
Run time error 7 was due to my mistake. In my original data, ClearData was like deleting the headings of sheet B. Rectified once I rebooted the computer. That is why I changed the message. The full code: -
Option Explicit
Sub GenerateXML()
UnHideSheets
    Application.ScreenUpdating = False
'
    Dim FirstRunComplete        As Boolean
    Dim ColumnK_Number          As Long
    Dim CurrentRowColumnM_Value As Long
    Dim DesiredMatchRowNumber   As Long
    Dim FormulaLooper           As Long
    Dim i                       As Long, ini        As Long, j      As Long, k  As Long
    Dim InnerFormulaLooper      As Long
    Dim LastColumnNumberSheetB  As Long
    Dim LastRow                 As Long
    Dim MatchCount              As Long
    Dim OccurrenceCounter       As Long
    Dim RangeK_FormulaRows      As Long
    Dim RowNumber               As Long
    Dim VchNo                   As Long
    Dim cell                    As Range
    Dim Fnd                     As Range
    Dim rFound                  As Range
    Dim rngReferenceRange       As Range, rngToCopy As Range
    Dim LastColumnLetterSheetB  As String
    Dim NewName                 As String
    Dim a                       As Variant, b       As Variant, c   As Variant
    Dim ColumnI_Array           As Variant
    Dim RangeK_Array            As Variant
    Dim WS                      As Worksheet

'
'-----------------------------------------------------------------------------------------
'
    With Sheets("Bank")                                                                         ' Copy Columns A:I from 'Original' to 'Bank'
        Sheets("Original").Columns("A:I").Copy .Range("A1")
        .UsedRange.UnMerge
        Set Fnd = .Range("A:A").Find("Date", , , xlPart, xlByRows, xlNext, False, , False)
        If Not Fnd Is Nothing And Fnd.Row > 1 Then ini = Fnd.Row + 2 Else ini = 1               ' If "Date" found in Column A in row>1 then set ini to 2 rows down
        a = .Range("A" & ini, .Range("I" & .Rows.Count).End(3)).Value                           ' Load array 'a' with the data from Columns A:I
    End With
'
    ReDim b(1 To UBound(a), 1 To 7)
    ReDim c(1 To UBound(a), 1 To 7)
'
    For i = 1 To UBound(a) - 3
        If LCase(a(i, 3)) <> LCase("(as per details)") And a(i, 6) <> "" Then               ' If Column C value <> '(as per details)' & column F value <> "" then...
            j = j + 1
            b(j, 1) = i 'Line                                                               '   save row# & all column values A:I except B,D,E to array 'b'
            b(j, 2) = a(i, 1) 'Date
            b(j, 3) = a(i, 6) 'Vch Type
            b(j, 4) = a(i, 7) 'Vch No.
            b(j, 5) = a(i, 3) 'Particulars
            b(j, 6) = a(i, 8) 'Debit
            b(j, 7) = a(i, 9) 'Credit
        Else                                                                                ' Else
            k = k + 1
            c(k, 1) = i 'Line
            c(k, 2) = a(i, 1) 'Date                                                         '   save row# & all other column values A:I except B,D,E to array 'c'
            c(k, 3) = a(i, 6) 'Vch Type
            c(k, 4) = a(i, 7) 'Vch No.
            c(k, 5) = a(i, 3) 'Particulars
            c(k, 6) = a(i, 8) 'Debit
            c(k, 7) = a(i, 9) 'Credit
        End If
    Next
'
    With Sheets("Bank")
        .UsedRange.Clear                                                                                        ' Clear the data that we copied to 'Bank'
        .Range("A1:G1").Value = Array("Line", "Date", "Vch Type", "Vch No.", "Particulars", "Debit", "Credit")  ' add headers
        .Range("A2").Resize(j, 7).Value = b                                                                     ' Display array 'b' to sheet
        .Range("A" & j + 3).Resize(k, 7).Value = c                                                              ' display array 'c' to sheet
'
'       Format the data
        .Columns("F:G").NumberFormat = "0.00"
        .UsedRange.EntireColumn.AutoFit
        .UsedRange.HorizontalAlignment = xlLeft
        .Range("B:B").NumberFormat = "dd-mm-yyyy"
    End With
'
    NewName = Sheets("Original").Range("K1")                                                                    ' Get name saved in 'Original' K1
    VchNo = 1000                                                                                                ' Initialize VchNo = 1000
'
    For Each cell In Sheets("Bank").Range("D2:D" & Sheets("Bank").Range("E" & Sheets("Bank").Rows.Count).End(xlUp).Row)
        If Not cell.Offset(, -1) = vbNullString Then                                                            ' Check for non blanks to left of Column D values
            VchNo = VchNo + 1
            cell.Value = VchNo                                                                                  ' Renumber VchNo's
        End If
'
        If cell.Offset(0, 1) = "(as per details)" Then cell.Offset(0, 1).Value = NewName                        ' If cell to right of Column D value =
'                                                                                                               '   (as per details)' then rename that cell value
    Next
'
    Set rngReferenceRange = Sheets("Bank").Range("A1").CurrentRegion
    Set rngToCopy = Sheets("Bank").Cells(rngReferenceRange.Rows.Count + 2, 1).CurrentRegion
'
    rngToCopy.Copy                                                                                              ' Copy now updated former array 'c' values
'
'---------------------------------------------------------------------------------------------------------------------
'
    With Sheets("A")
        .Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False  ' Paste now updated former array 'c' values to 'A'
        Application.CutCopyMode = False
'
        .Columns("B:B").NumberFormat = "dd-mm-yyyy"
        .Columns("E:E").Insert Shift:=xlToRight
        .Columns("G:H").Insert Shift:=xlToRight
'
        .Range("G1").FormulaR1C1 = "=IF(RC[2]="""","""",-RC[2])"
        .Range("H1").FormulaR1C1 = "=IF(RC[2]="""","""",RC[2])"
        .Range("G1:H1").AutoFill Destination:=.Range("G1:H" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    End With
'
    With Sheets("A").Range("B2:D" & Sheets("A").Range("A" & Rows.Count).End(xlUp).Row)
        .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"                                                 ' Fill blank cells in Columns B:D with cell value above it
        .Value = .Value
    End With
'
    With Sheets("A")
        .Columns("D").NumberFormat = "0"
        .Columns("G:H").NumberFormat = "0.00"
'
        .Range("B1:H1", .Range("B1:H1").End(xlDown)).Copy
        .Range("B1:H1", .Range("B1:H1").End(xlDown)).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'
        .Range("B1:H1", .Range("B1:H1").End(xlDown)).Copy Sheets("B").Range("A3")
    End With
'
'
'   This should be a good place to evaluate the formulas for Sheets("B") ;)
'
    ColumnK_Number = 11
    RowNumber = 3
    LastColumnLetterSheetB = Split(Sheets("B").Range("K2").End(xlToRight).Address, "$")(1)                  ' Get last column letter used in row 2 of Sheets("B")
    LastColumnNumberSheetB = Sheets("B").Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column    ' Find last column # used in Sheets("B")
'
    Set WS = Worksheets("B")
    LastRow = WS.Range("A" & Rows.Count).End(xlUp).Row
'
'--------------------------------------------------------------------------------------------------------------------------------------
'
    ReDim ColumnI_Array(1 To LastRow - 2)
'
    For FormulaLooper = RowNumber To LastRow                                                                                            ' Column I formulas
        ColumnI_Array(FormulaLooper - 2) = WS.Evaluate("=IF(A2="""","""",SUM(F" & FormulaLooper & ":G" & FormulaLooper & "))")
    Next
'
    WS.Range("I3:I" & LastRow) = Application.Transpose(ColumnI_Array)
'
'--------------------------------------------------------------------------------------------------------------------------------------
'
'   Count cells that are not blank in Sheets("B") Column E to get # of formula rows needed for Sheets("B") Columns K3 range ;)
    RangeK_FormulaRows = Application.WorksheetFunction.CountIf(Sheets("B").Range("E3:E" & LastRow), Sheets("Original").Range("K1"))
'
    ReDim RangeK_Array(1 To RangeK_FormulaRows, 1 To LastColumnNumberSheetB - ColumnK_Number + 1)
'
    For FormulaLooper = RowNumber To RowNumber + RangeK_FormulaRows - 1
        OccurrenceCounter = OccurrenceCounter + 1
'
        Set rFound = WS.Range("E2:E" & LastRow).Cells(1, 1)
'
        For MatchCount = 1 To OccurrenceCounter
            Set rFound = WS.Range("E2:E" & LastRow).Find(Sheets("Original").Range("K1"), rFound, xlValues, xlWhole)
        Next
'
        DesiredMatchRowNumber = rFound.Row
        CurrentRowColumnM_Value = WS.Evaluate("=IFERROR(INDEX($C$3:$C$" & LastRow & "," & DesiredMatchRowNumber & "),"""")")
'
        RangeK_Array(FormulaLooper - 2, 1) = WS.Evaluate("=IFERROR(INDEX($A$3:$I$" & LastRow & ",MATCH(" & _
            CurrentRowColumnM_Value & ",$C$3:$C$" & LastRow & ",0),1),"""")")                                                       ' Save $K3 value
'
        RangeK_Array(FormulaLooper - 2, 2) = WS.Evaluate("=IFERROR(INDEX($A$3:$I$" & LastRow & ",MATCH(" & _
            CurrentRowColumnM_Value & ",$C$3:$C$" & LastRow & ",0),2),"""")")                                                       ' Save $L3 value
'
        RangeK_Array(FormulaLooper - 2, 3) = WS.Evaluate("=IFERROR(INDEX($C$3:$C$" & LastRow & "," & _
            DesiredMatchRowNumber & "),"""")")                                                                                      ' Save $M3 value
'
        RangeK_Array(FormulaLooper - 2, 4) = WS.Evaluate("=IF(IFERROR(INDEX($A$3:$I$" & LastRow & _
            ",AGGREGATE(15,6,(ROW($C$3:$C$" & LastRow & ")-ROW($C$2))/($C$3:$C$" & LastRow & "=" & _
            CurrentRowColumnM_Value & "),INT((COLUMNS(N" & FormulaLooper + 1 & ":$O" & FormulaLooper + 1 & _
            ")+1)/2)),4),"""")="""","""")")                                                                                         ' Save $N3 value
'
        RangeK_Array(FormulaLooper - 2, 5) = WS.Evaluate("=IF(" & CurrentRowColumnM_Value & _
            "="""","""",IFERROR(INDEX($A$3:$I$" & LastRow & ",AGGREGATE(15,6,(ROW($C$3:$C$" & LastRow & _
            ")-ROW($C$2))/($C$3:$C$" & LastRow & "=" & CurrentRowColumnM_Value & "),INT((COLUMNS(O" & _
            FormulaLooper + 1 & ":$O" & FormulaLooper + 1 & ")+1)/2)),5),""""))&""""")                                              '  Save $O3 value
'
        For InnerFormulaLooper = 5 To 45 Step 2
            If FirstRunComplete Then
                RangeK_Array(FormulaLooper - 2, InnerFormulaLooper + 1) = WS.Evaluate("=IF(" & RangeK_Array(FormulaLooper - 3, 3) & _
                    "="""","""",IFERROR(INDEX($A$3:$I$" & LastRow & ",AGGREGATE(15,6,(ROW($C$3:$C$" & LastRow & _
                    ")-ROW($C$2))/($C$3:$C$" & LastRow & "=" & CurrentRowColumnM_Value & "),INT((COLUMNS($O" & _
                    FormulaLooper & ":" & WS.Range("K" & FormulaLooper).Offset(, InnerFormulaLooper).Address(0, 0) & _
                    ")+1)/2)),9),""""))")
            Else
                RangeK_Array(FormulaLooper - 2, InnerFormulaLooper + 1) = WS.Evaluate("=IF(M" & FormulaLooper - 1 & _
                    "="""","""",IFERROR(INDEX($A$3:$I$" & LastRow & ",AGGREGATE(15,6,(ROW($C$3:$C$" & LastRow & _
                    ")-ROW($C$2))/($C$3:$C$" & LastRow & "=" & CurrentRowColumnM_Value & "),INT((COLUMNS($O" & _
                    FormulaLooper & ":" & WS.Range("K" & FormulaLooper).Offset(, InnerFormulaLooper).Address(0, 0) & _
                    ")+1)/2)),9),""""))")
            End If
        Next
'
        For InnerFormulaLooper = 6 To 44 Step 2
            If FirstRunComplete Then
                RangeK_Array(FormulaLooper - 2, InnerFormulaLooper + 1) = WS.Evaluate("=IF(" & RangeK_Array(FormulaLooper - 3, 3) & _
                    "="""","""",IFERROR(INDEX($A$3:$I$" & LastRow & ",AGGREGATE(15,6,(ROW($C$3:$C$" & LastRow & _
                    ")-ROW($C$2))/($C$3:$C$" & LastRow & "=" & CurrentRowColumnM_Value & "),INT((COLUMNS($O" & _
                    FormulaLooper + 1 & ":" & WS.Range("K" & FormulaLooper).Offset(1, InnerFormulaLooper).Address(0, 0) & _
                    ")+1)/2)),5),""""))&""""")
            Else
                RangeK_Array(FormulaLooper - 2, InnerFormulaLooper + 1) = WS.Evaluate("=IF(M" & FormulaLooper - 1 & _
                    "="""","""",IFERROR(INDEX($A$3:$I$" & LastRow & ",AGGREGATE(15,6,(ROW($C$3:$C$" & LastRow & _
                    ")-ROW($C$2))/($C$3:$C$" & LastRow & "=" & CurrentRowColumnM_Value & "),INT((COLUMNS($O" & _
                    FormulaLooper + 1 & ":" & WS.Range("K" & FormulaLooper).Offset(1, InnerFormulaLooper).Address(0, 0) & _
                    ")+1)/2)),5),""""))&""""")
            End If
        Next
'
        FirstRunComplete = True
    Next
'
    WS.Range("K3:" & LastColumnLetterSheetB & RangeK_FormulaRows + 2) = RangeK_Array
'
'
    Dim Mx As Long
'
'   this range needs to be changed
    With Sheets("B")
        Mx = Application.Max(.Range("K3:K" & .Range("K" & .Rows.Count).End(xlUp).Row))
'
        Sheets("E").Range("A3:AT3").Resize(Mx).Value = .Range("K3:" & LastColumnLetterSheetB & "3").Resize(Mx).Value
    End With
'
    Sheets("F").Range("B2:AT2").Resize(Mx).Value = Sheets("E").Range("A3:AT3").Resize(Mx).Value
'
'
    Sheets("Bank").Select
    Range("A1").Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
'
    Sheets("Z").Select
    Range("A2").Select
    ActiveSheet.Paste
'
'
    With Sheets("Z")
        .UsedRange.EntireColumn.AutoFit
        .Columns("F:G").Insert Shift:=xlToRight
        .Range("F3").FormulaR1C1 = "=IF(RC[2]="""",RC[3],-RC[2])"
        .Range("G3").FormulaR1C1 = "=-RC[-1]"
'
'       this range needs to be changed
        .Range("F3:G3").AutoFill Destination:=.Range("F3:G" & .Range("A" & .Rows.Count).End(xlUp).Row)
'''        .Range("F2:G2").AutoFill Destination:=.Range("F2:G" & .Range("G" & .Rows.Count)).End(xlUp).Row
'
'       this range needs to be changed
''        .Range("F2:G2000").Select
        .Range("F3:G3", .Range("F3:G3").End(xlDown)).Copy
        .Range("F3:G3").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
'
    Application.CutCopyMode = False
'
    Dim rr      As Long
    Dim p       As Variant
    Dim pp      As Variant
    Dim s()     As Variant
    Dim ss()    As Variant
'
    s = Array(2, 3, 4, 5, 6, 7)
    ss = Array(2, 3, 4, 8, 7, 9)
    p = Sheets("Z").Cells(Sheets("Z").Rows.Count, 1).End(3).Row
    pp = Sheets("F").Cells(Sheets("F").Rows.Count, 3).End(3).Row + 1
'
    For rr = 0 To UBound(s)
        Sheets("Z").Range(Sheets("Z").Cells(3, s(rr)), Sheets("Z").Cells(p, s(rr))).Copy Sheets("F").Cells(pp, ss(rr))
    Next
'
    Sheets("F").Cells(pp, "f").Resize(Sheets("F").Range("b" & Sheets("Z").Rows.Count).End(3).Row - pp + 1) = NewName
'
    Application.CutCopyMode = True
'
''    With Sheets("Z").UsedRange
''        .Value = .Value
''    End With
'
    Dim da As Long
    Dim ku As Long
'
    With Sheets("F").Range("A1").CurrentRegion
        For da = 2 To .Rows.Count
            If .Cells(da, 7) < 0 Then
                ku = .Cells(da, .Columns.Count).End(xlToLeft).Column
                .Cells(da, ku + 1).Resize(, 2).Value = .Cells(da, 6).Resize(, 2).Value
'
                With .Cells(da, 6).Resize(, .Columns.Count)
                    .Value = .Offset(, 2).Value
                End With
            End If
        Next
    End With
'
    With Sheets("F")
        .UsedRange.HorizontalAlignment = xlGeneral
        .Range("D2", .Range("D2").End(xlDown)).ClearContents
    End With
'
    Sheets("Original").Activate
    Range("A2").Select
'
    
    
Dim rngData As Range
Dim strData As String
Dim strTempFile As String
Dim x As Long, y As Long
Dim usr As String
Sheets("ImportData").Activate
y = Sheets("ImportData").Range("A2").CurrentRegion.Columns.Count
x = Sheets("F").Range("B2:B" & Sheets("F").Range("B" & Rows.Count).End(xlUp).Row).Rows.Count
Range("A2").Resize(x, y).Copy
    With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        .GetFromClipBoard
        strData = .GetText
    End With
    usr = Environ("username")
    strTempFile = "C:\Users\" & usr & "\Desktop\Bank.xml"
    With CreateObject("Scripting.FileSystemObject")
        .CreateTextFile(strTempFile, True).Write strData
     End With
     Sheets("Original").Activate
      Range("A2").Select

    ActiveSheet.Shapes.Range(Array("Button 3")).Select
    ActiveSheet.Shapes("Button 3").ZOrder msoSendBackward
    Range("K9").Select
        
Application.ScreenUpdating = True
'
HideSheets
MsgBox ("File saved on Desktop as Bank.XML Copy path and paste in tally.")

End Sub

Rich (BB code):
Option Explicit

Sub ClearData()
UnHideSheets
    
    Application.ScreenUpdating = False                                                                      ' Turn ScreenUpdating off
    Application.Calculation = xlManual                                                                      ' Turn Calculation's off
'
    Dim LastRowInSheetB         As Long, LastRowInSheetF            As Long
    Dim LastColumnLetterSheetB  As String, LastColumnLetterSheetF   As String
    Dim WS                      As Worksheet
'
    LastColumnLetterSheetB = Split(Sheets("B").Range("K2").End(xlToRight).Address, "$")(1)                  ' Get last column letter used in row 2 of Sheets("B")
    LastColumnLetterSheetF = Split(Cells(1, (Sheets("F").Cells.Find("*", , xlFormulas, , xlByColumns, _
            xlPrevious).Column)).Address, "$")(1)                                                           ' Get last column letter used in Sheets("F")
    LastRowInSheetB = Sheets("B").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row                 ' Find last row # used in Sheets("B")
    LastRowInSheetF = Sheets("F").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row                 ' Find last row # used in Sheets("F")
'
    For Each WS In Sheets(Array("Bank", "A", "E", "Z"))                                                     ' Prep sheets to clear ranges
        With WS                                                                                             '   With each worksheet to be cleared ...
            .UsedRange.Clear                                                                                '       Clear the data from all used cells
        End With
    Next                                                                                                    ' Loop back for next sheet to be cleared
'
    Sheets("B").Range("A3:" & LastColumnLetterSheetB & LastRowInSheetB).ClearContents                       ' Clear contents of cells in Sheets("B")
    Sheets("F").Range("B2:" & LastColumnLetterSheetF & LastRowInSheetF).ClearContents                       ' Clear contents of cells in Sheets("F")
'
    Application.Calculation = xlAutomatic                                               ' Turn Calculations back on
    Application.ScreenUpdating = True      ' Turn ScreenUpdating back on
         
    HideSheets

     ActiveSheet.Shapes.Range(Array("Button 5")).Select
     ActiveSheet.Shapes("Button 5").ZOrder msoSendBackward
     Sheets("Original").Range("K1").Select
 MsgBox ("Data Cleared. Replace with New Data in columns A1:I1 to Generate XML.")
End Sub

Rich (BB code):
Rich (BB code):
Option Explicit

Sub HideSheets()
    Dim WS As Worksheet
        For Each WS In ThisWorkbook.Worksheets
        If WS.Name <> "Original" Then
        WS.Visible = xlSheetVeryHidden
        End If
    Next WS
    
End Sub

Sub UnHideSheets()
    Dim WS As Worksheet
        For Each WS In ThisWorkbook.Worksheets
        If WS.Name <> "Original" Then
            WS.Visible = xlSheetVisible
            
        End If
    Next WS
    
End Sub
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I'm confused. Why are you checking for 'Original' sheet when unhiding?
 
Upvote 0
The original sheet is the only unhidden sheet. The user has to paste the data in columns A:J, press generate xml and when the xml is created on the desktop press clear data. Then a new data is pasted in columns A:J and so on....
 
Upvote 0
I wanted the code to run 100% perfect so that I could place the buttons one on top of the other so that the user can know whether to press generate xml or clear data.
 
Upvote 0
As you just stated, 'Original' sheet is unhidden.

so why the code:
VBA Code:
[CODE]        If WS.Name <> "Original" Then
            WS.Visible = xlSheetVisible
[/CODE]
The sheet is already unhidden
 
Upvote 0
As you just stated, 'Original' sheet is unhidden.

so why the code:
VBA Code:
[CODE]        If WS.Name <> "Original" Then
            WS.Visible = xlSheetVisible
[/CODE]
The sheet is already unhidden
I have to enter the data somewhere to generate xml, right. So the Original sheet is unhidden.
 
Upvote 0
It looks like this when you open this workbook.
Working code of JohnnyL 10.01.2022.xlsm
ABCDEFGHIJK
1 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Original
Cell Formulas
RangeFormula
K1K1=IFERROR(LEFT(A3, LEN(A3) - 6),"")
 
Upvote 0
As there are number of working sheets, I want to hide and unhide them except original sheet when the code is in process.
 
Upvote 0
What I am saying is both your hide and unhide code exempts the 'Original sheet, therefore it is always unhidden.

So why not use the the following for your unhidden block of code:
VBA Code:
Sub UnHideSheets()
    Dim WS As Worksheet
        For Each WS In ThisWorkbook.Worksheets
            WS.Visible = xlSheetVisible
        End If
    Next WS
End Sub

No need to check for it's name.
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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