[VBA] If IsNull = False - Help (Offset/Shift/Move Value)

timdecker

New Member
Joined
May 7, 2013
Messages
37
I am having an issue manipulating a flat file. I sometimes have values in extended columns, rather than below onto the next row. How can I shift/offset these values to the rows below. I have 2 grids below, one with an example as it is now and another of what I would like to occur. The values that change will be in red. The values in red are sporadic, in terms of which flat file they show up in.

Thanks!

Example File:
C6= Peak Found14.7413236.29
C6toC7 Peak Found17.37773.62
HeptaneorC7= Peak Found19.1510800.4
>C7 Peak Not Found
Extra peaks found in chromatogram
Retention Time(min) Peak Area
2.47464.01 6.9495.23
C3 042116 21.1_summary.txt
Peaks found (and not found) in chromatogram
Name Found/Not Found Retention Time(min) Peak Area
Methane Peak Not Found
Ethane Peak Found2.7710.92
C5toC6 Peak Found12.76993.91
C6= Peak Found15.04906.85
C6toC7 Peak Found17.35632.29
HeptaneorC7= Peak Found19.14515.58
>C7 Peak Not Found
Extra peaks found in chromatogram
Retention Time(min) Peak Area
2.46423.42 4.556.5556.222.88
C3 042116 22.1_summary.txt

<colgroup><col><col><col><col><col span="6"></colgroup><tbody>
</tbody>


Wanted Outcome:
C6= Peak Found14.7413236.29
C6toC7 Peak Found17.37773.62
HeptaneorC7= Peak Found19.1510800.4
>C7 Peak Not Found
Extra peaks found in chromatogram
Retention Time(min) Peak Area
2.47464.01
6.9495.23
C3 042116 21.1_summary.txt
Peaks found (and not found) in chromatogram
Name Found/Not Found Retention Time(min) Peak Area
Methane Peak Not Found
Ethane Peak Found2.7710.92
C5toC6 Peak Found12.76993.91
C6= Peak Found15.04906.85
C6toC7 Peak Found17.35632.29
HeptaneorC7= Peak Found19.14515.58
>C7 Peak Not Found
Extra peaks found in chromatogram
Retention Time(min) Peak Area
2.46423.42
4.556.55
56.222.88
C3 042116 22.1_summary.txt

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You are forgetting to disclose that you have this cross posted at 2 other sites.
 
Upvote 0
Last edited:
Upvote 0
Well, thanks for getting me on the right track everyone, especially 6StringJazzer @ EF. Here is the final product:

Code:
Dim row, col, loopCounter As Integer
row = 1
loopCounter = 1
Do While (row <= LastRow)
    For col = 5 To lColumn
        If (col Mod 2 <> 0) Then
            If (Cells(row, col).Value <> "") Then
                'Debug.Print row & "," & col
                Cells(row, col).Offset(loopCounter).EntireRow.Insert
                Cells(row + loopCounter, 3) = Cells(row, col)
                Cells(row + loopCounter, 4) = Cells(row, col + 1)
                loopCounter = loopCounter + 1
                'Debug.Print "counter " & loopCounter
            End If
        End If
    Next col
    LastRow = LastRow + loopCounter - 1
    'Debug.Print "new last row = " & LastRow
    loopCounter = 1
    row = row + 1


Loop
 
Upvote 0
Sorry, left out the rest of the code:

Code:
Sub M()
     
    Dim LastRow As Long
    Dim lColumn As Long 'last column
    Dim lc As Integer
    Dim row As Integer
    Dim col As Integer
    Dim loopCounter As Integer


    lColumn = ActiveSheet.UsedRange.column + ActiveSheet.UsedRange.Columns.Count - 1
    LastRow = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).row
    
    'save last column number in used range
    lc = ActiveSheet.Cells.SpecialCells(xlLastCell).column


    Columns(9).Delete
    Columns(8).Delete
    
    'Loop for each column number until it equals 0
    Do Until lc = 0
        If WorksheetFunction.CountA(Columns(lc)) = 0 Then
            Columns(lc).Delete
        End If
        'proceeds to the next lowest column number
        lc = lc - 1
        
    Loop


    row = 1
    loopCounter = 1
    Do While (row <= LastRow)
        For col = 5 To lColumn
            If (col Mod 2 <> 0) Then
                If (Cells(row, col).value <> "") Then
                    'Debug.Print row & "," & col
                    Cells(row, col).Offset(loopCounter).EntireRow.Insert
                    Cells(row + loopCounter, 3) = Cells(row, col)
                    Cells(row + loopCounter, 4) = Cells(row, col + 1)
                    loopCounter = loopCounter + 1
                    'Debug.Print "counter " & loopCounter
                End If
            End If
        Next col
        LastRow = LastRow + loopCounter - 1
        Debug.Print "new last row = " & LastRow
        loopCounter = 1
        row = row + 1
    
    Loop
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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