PDA

View Full Version : Help... I am so lost



Porkypig
05-11-2007, 11:02 AM
I have a spreadsheet that consists of Inv_no, Charge Description and Charge Amount as shown in Sheet3.

For every inv_no change, a blank row will need to insert below.
After complete the checking of column A; shift column B2:C12 down a row.
Delete the duplicate inv_no in Column A; ie. those inv_no highlighted in yellow under Column A. Any help on how to code it.

Have attached a sample.


:dunno

vonpookie
05-11-2007, 11:55 AM
Would this work for you?

Sub asdf()
Dim Lrow As Long, i As Long
Dim Rng As Range, rngTemp As Range

Lrow = Columns(1).Find("*", searchdirection:=xlPrevious).Row

i = 2
Do Until i > Lrow
If Cells(i, 1) <> "" And Cells(i, 1) <> Cells(i + 1, 1) Then
Rows(i + 1).Insert shift:=xlDown
Lrow = Lrow + 1
End If
i = i + 1
Loop

Lrow = i - 1

Set Rng = Range("A1:A" & Lrow)
Set rngTemp = Rng.Offset(, 3)

Rng.AdvancedFilter xlFilterInPlace, unique:=True
With rngTemp
.SpecialCells(xlVisible) = "x"
ActiveSheet.ShowAllData
.SpecialCells(xlBlanks).Offset(, -3).ClearContents
.ClearContents
End With

Range("B2:C2").Insert shift:=xlDown

End Sub

Porkypig
05-11-2007, 12:20 PM
Oh... you're champion.... this work perfectly. Thanks you so much.:beerchug:

Charlize
05-11-2007, 12:24 PM
Since I began with this, I came up with this one.Sub Make_it_beautiful()
Dim row As Long
row = Range("A" & Rows.Count).End(xlUp).row
Do While row > 1
If Range("A" & row).Offset(-1, 0).Value = _
Range("A" & row).Value Then
Range("A" & row).ClearContents
Else
Range("A" & row).EntireRow.Insert
Range("A" & row).Offset(1, 0).Cut Range("A" & row)
End If
row = row - 1
Loop
End SubCharlize