So essentially, you're trying to compact each column--get rid of multiple
consecutive empty cells and replace them with a single empty cell?
This will work if the data is all values--no formulas. (Is that ok?)
Option Explicit
Sub testme01()
Dim CurWks As Worksheet
Dim NewWks As Worksheet
Dim DestCell As Range
Dim RngToCopy As Range
Dim myArea As Range
Dim myRng As Range
Dim myCol As Range
Set CurWks = ActiveSheet
Set NewWks = Worksheets.Add
Set DestCell = NewWks.Range("A1")
With CurWks
'remove the ""
.Cells.Replace What:=Chr(34) & Chr(34), Replacement:="", _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
MatchCase:=False
For Each myCol In .UsedRange.Columns
Set myRng = Nothing
On Error Resume Next
Set myRng = myCol.Cells.SpecialCells(xlCellTypeConstants)
On Error GoTo 0
If myRng Is Nothing Then
'do nothing!
Else
For Each myArea In myRng.Areas
With myArea
Set RngToCopy = .Resize(.Rows.Count + 1, 1)
End With
RngToCopy.Copy _
Destination:=DestCell
Set DestCell = DestCell.Offset(RngToCopy.Rows.Count)
Next myArea
End If
'get ready for next column
Set DestCell = NewWks.Cells(1, DestCell.Column + 1)
Next myCol
End With
End Sub
Thomas Toth wrote:
>
> Dave Peterson wrote:
> > So you're trying to make those duplicated cell look like ditto marks?
> >
> > How about an alternative?
> >
> > Keep the data and lose the ditto marks. But use format|conditional formatting
> > to make the duplicated cells look empty (white font on white fill, for example).
> >
> > It'll make working with your data (sorting/filtering/charting/etc) much easier
> > if you keep the data.
> >
> > If you want to try, visit Debra Dalgleish's site:
> > http://contextures.com/xlCondFormat03.html#Duplicate
> >
> > Thomas Toth wrote:
> >> Hi,
> >>
> >> I'm trying to get a second table which contains all elements of each
> >> column of the first one, except that the empty-string-output cells ("")
> >> are removed, but one. The first table should remain, the second one can
> >> be either calculated or copied in some way.
> >>
> >> I have a formula in every cell which calculates a value. If the result
> >> is not valid, the formula will output "" (empty string). Due to my data
> >> structure there are many empty-string cells between two blocks of values
> >> in each column. I would like to remove all of them, except one, such
> >> that the two blocks are separated by one empty cell in each column.
> >> Empty is ok, I don't need the values/formulas, it is the final output table.
> >>
> >> My original table contains the names across, and alpha-numerical values
> >> down the column, with possible "" from formulas inbetween. Like this:
> >>
> >> Table1 (what I have):
> >>
> >> Name1 Name2 Name3 Name4
> >> E123 E2343 "" E3432
> >> E354 "" "" F3437
> >> N324 "" "" N54323
> >> E634 "" "" ""
> >> "" "" "" ""
> >> "" "" "" ""
> >> "" "" "" ""
> >> I4325 N6377 N3245 G2307
> >> E6543 E5233 "" N29374
> >> N987 N4353 "" ""
> >> G8377 "" "" ""
> >> "" "" "" ""
> >>
> >> Table2 (what I need):
> >>
> >> Name1 Name2 Name3 Name4
> >> E123 E2343 -- E3432
> >> E354 -- N3245 F3437
> >> N324 N6377 N54323
> >> E634 E5233 --
> >> -- N4353 G2307
> >> I4325 N29374
> >> E6543
> >> N987
> >> G8377
> >>
> >> where -- represents a blank/empty cell.
> >>
> >> I tried copying and pasting with removing blanks but that doesn't work
> >> as they are considered non-empty because of the formulas, even if I tick
> >> to only paste the values. Copy-paste with a filter won't work as there
> >> isn't enough space left on the sheet, and it would become impractical to
> >> use. Besides, I think I tried that too. VBA is not an option either.
> >>
> >> Any ideas how I could get the second table?
> >>
> >> Thanks for any help,
> >>
> >> Thomas
> >
> Hi Dave,
>
> well, not realy. I'm trying to make those multiple lines of dito marks
> like a single empty cell. I don't care about the values and formulas in
> table 2 as there is no further processing. Although I wouldn't mind if
> it was a dynamic solution which I can somehow 'calculate' from table 1,
> to save me having to copy them every time I use the tables.
>
> So, speaking for column A, I would like to have only a one cell gap
> between the values E634 and I4325, compared to 3 cells in table 1.
>
> I don't have a problem with formating as an empty string, represented by
> "", will not show in excel. I understand your solution but it will still
> leave more than a 1 cell gap between the two blocks, even if they are blank.
>
> Thanks for your help anyway,
>
> Tom
--
Dave Peterson