• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA// Need to add additional column as per condition to make structured Data

riya

Member
Hi All,
I have to arrange the data in the below column form, I am using the below code but when we add column all structure got mess up. Please see the attached file.

1 2 3 4

Code:
ival2 = Sheet2.Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To ival2 Step 1
IF Cells(4, i).Value <> "4" Then
        Columns(i).Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Application.ScreenUpdating = False
    Cells(4, i).Value = "4"
    
    End If
  
       Next

IF Cells(4, i).Value <> "3" Then
        Columns(i).Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Application.ScreenUpdating = False
    Cells(4, i).Value = "3"
 
    End If
  
       Next
END SUB

Mod Edit: Code tags added
 

Attachments

  • SORTINGG.xlsb
    17.9 KB · Views: 1
Last edited by a moderator:
riya
How many different variations do You have these?
Test this ... press [Do It] (below Your 'InPut')
 

Attachments

  • SORTINGG.xlsb
    49.9 KB · Views: 4
Back
Top