Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:42:53+00:00 2026-06-16T02:42:53+00:00

I have an excel,where near about 156 columns and 2000 rows.Here 36 tasks are

  • 0

I have an excel,where near about 156 columns and 2000 rows.Here 36 tasks are being audited,where each taks has been described by 4 columns – say “Task1 Name”,”Task1 Start Date”,”Task1 Completion Date”,”Total Time Spent in Task1″.Now some times each of such 4 columns can have values for all and some times all the 4 columns dodes not have values to it.Now Goal is to find out such a 4-tuple set where atleast a single column data present.But if the data is not present then it will be told as unwanted set.So i need such unwanted columns to get moved one side and the partially filed or fullyfiled data in one side.But Non null dataset will move from right to left if its immediate preceded has 4 blank columns,otherwise or not. Find the input table below:

enter image description here

enter image description here

enter image description here

EDIT:

  Sub DataShiftFromLeftToRight(Ob6)


Dim count 
Dim dataArray 
Dim height 
Dim width 
Dim rWidth 
Dim packArray 
Dim i 
Dim j
dim rowArray
dim ColumnInGroup
dim k 
dim b 
    With Ob6 
    .activate
    ColumnInGroup= 4
    height = .Cells(.Rows.count, 1).End(-4162).Row
' assume 1st line is header
' start from 2nd line
If height > 1 Then
    For i = 2 To height'Number of rows

        width = .Cells(i, .Columns.count).End(-4159).Column
        'round width
        'MsgBox(width)
        if (width -1 )mod columnInGroup <> 0 then  
            width = (((width -1)\columnInGroup )+1)* columnInGroup + 1
        end if
        if width > 1 then 'need to change to the column number
            'finding the last unit originally packed 
            redim rowArray(0,width-1)
            rowArray = .range(.cells(i,1), .cells(i,width)).value'here 1 need to change
            'default value
            rWidth = width
            for j = 2 to width  step ColumnInGroup'here j need to change
                if j+ColumnInGroup -1 <= width then 
                    b = false
                    for k = 0 to ColumnInGroup - 1
                        if rowArray(1,j+k) <> "" then 
                            b = true 
                            exit for 
                        end if
                    next 
                    if not b then 
                        rWidth = j - 1
                        exit for
                    end if
                else
                    rWidth = width
                end if
            next

            If width > rWidth Then
                ReDim dataArray(1 ,(width - rWidth))
                dataArray = .Range(.Cells(i, rWidth + 1), .Cells(i, width)).Value

                count = 0

                For j = LBound(dataArray, 2) To UBound(dataArray, 2) Step ColumnInGroup
                    if j+ColumnInGroup - 1<= ubound(dataArray,2) then 
                        b = false
                        for k = 0 to ColumnInGroup - 1
                            if dataArray(1,j+k) <> "" then 
                                b = true 
                                exit for 
                            end if
                        next 
                        if  b then 
                            count = count + 1
                        end if
                    else
                        exit for
                    end if
                Next

                ReDim packArray(0, count * columnInGroup - 1)
                count = 0
                For j = LBound(dataArray, 2) To UBound(dataArray, 2) Step columnInGroup
                    ' we found a "T" Unit
                    if j+columnInGroup -1<= ubound(dataArray,2) then 
                        b = false
                        for k = 0 to ColumnInGroup - 1
                            if dataArray(1,j+k) <> "" then 
                                b = true 
                                exit for 
                            end if
                        next 
                        if  b then 
                            count = count + 1
                            for k = 0 to columnInGroup - 1
                                If j + k <= UBound(dataArray, 2) Then
                                    packArray(0, (count - 1) * columnInGroup  + k ) = dataArray(1, j + k)
                                end if
                            next 
                        end if

                    else
                        exit for
                    end if

                Next

                'clear original data
                .Range(.Cells(i, rWidth + 1), .Cells(i, width)).ClearContents

                'for j = 1 to ubound(packArray,2)
            '       .cells(i,rWidth+j).value = packArray(1,j)
            '   next 
                .Range(.Cells(i, rWidth + 1), .Cells(i, rWidth + count * columnInGroup)).Value = packArray

            End If
        end if
    Next

End If

End With

End Sub

But this is code no way producing correct data output..Please help me here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:42:54+00:00Added an answer on June 16, 2026 at 2:42 am

    This code shifts all ‘populated’ tasks to the left:

    Sub ShiftTasks()
    
        Dim wst As Excel.Worksheet
        Dim lRow As Long
        Dim lTask As Long
        Dim lCol As Long
    
        Const NUM_TASKS As Long = 36
        Const COL_FIRST As Long = 12
    
        Set wst = ActiveSheet
    
        With wst
    
            For lRow = 2 To .UsedRange.Rows.Count
                lTask = 1
                Do While lTask <= NUM_TASKS
                    lCol = COL_FIRST + (lTask - 1) * 4
                    If Len(.Cells(lRow, lCol).Value) = 0 And _
                       Len(.Cells(lRow, lCol + 1).Value) = 0 And _
                       Len(.Cells(lRow, lCol + 2).Value) = 0 And _
                       Len(.Cells(lRow, lCol + 3).Value) = 0 Then
                        ' make sure there is something to the right to shift over
                        If .Cells(lRow, lCol).End(xlToRight).Column < .Columns.Count Then
                            ' delete the empty cells and shift everything left``
                            .Range(.Cells(lRow, lCol), .Cells(lRow, lCol + 3)).Delete Shift:=xlToLeft
                        Else
                            ' force the loop to the next row
                            lTask = NUM_TASKS + 1
                        End If
                    Else
                        lTask = lTask + 1
                    End If
                Loop
            Next lRow
        End With
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an excel spreadsheet that has about 18k rows and three columns. I
I have an excel workbook that is used to track tasks by project. Each
I have excel sheet with N+1 rows where Column A has unique id N.
I have 12 excel files, each one with lots of data organized in 2
I have an excel sheet that has several headers. One of the header is
Until Office 2007, Excel has a maximum of 65,000 rows. Office 2007 bumped that
I have Excel data that looks like the top two rows of the following:
I have an Excel document that has a single column of strings (around 400
I have excel file with following columns Field1 Field2 Field3, Field4 =============================== 123 4
in excel i have a column which contains about 5 numbers cola num1 num2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.