Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Hierarchy Macro

I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Hierarchy Macro

One Way. This will identify the last used row and last used column in
your spreadsheet and cycle through til complete. If you want it to
cycle through different columns/rows, just change the values assigned
to the variables as needed.
Sub likeThis()
Dim sRow As Long, lRow As Long
Dim sCol As Integer, lCol As Integer
Dim found As Boolean
sRow = 1
sCol = 1
lRow = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
lCol = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
For i = sRow To lRow
found = False
For j = sCol To lCol
If found = False Then
If IsEmpty(Cells(i, j)) Then
Cells(i, j).Delete Shift:=xlToLeft
j = j - 1
Else
found = True
End If
Else
If IsEmpty(Cells(i, j)) Then _
Cells(i, j) = Cells(i, j).Offset(0, -1)
End If
Next j
Next i
End Sub

Jason Hall wrote:
I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Hierarchy Macro

I am sorry but, that macro didn't work at all. It pulled information from
incorrect cells and didn't match the diagram I provided.

Thanks though

"JW" wrote:

One Way. This will identify the last used row and last used column in
your spreadsheet and cycle through til complete. If you want it to
cycle through different columns/rows, just change the values assigned
to the variables as needed.
Sub likeThis()
Dim sRow As Long, lRow As Long
Dim sCol As Integer, lCol As Integer
Dim found As Boolean
sRow = 1
sCol = 1
lRow = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
lCol = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
For i = sRow To lRow
found = False
For j = sCol To lCol
If found = False Then
If IsEmpty(Cells(i, j)) Then
Cells(i, j).Delete Shift:=xlToLeft
j = j - 1
Else
found = True
End If
Else
If IsEmpty(Cells(i, j)) Then _
Cells(i, j) = Cells(i, j).Offset(0, -1)
End If
Next j
Next i
End Sub

Jason Hall wrote:
I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Hierarchy Macro

On Oct 25, 4:54 pm, Jason Hall
wrote:
I am sorry but, that macro didn't work at all. It pulled information from
incorrect cells and didn't match the diagram I provided.

Thanks though

"JW" wrote:
One Way. This will identify the last used row and last used column in
your spreadsheet and cycle through til complete. If you want it to
cycle through different columns/rows, just change the values assigned
to the variables as needed.
Sub likeThis()
Dim sRow As Long, lRow As Long
Dim sCol As Integer, lCol As Integer
Dim found As Boolean
sRow = 1
sCol = 1
lRow = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
lCol = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
For i = sRow To lRow
found = False
For j = sCol To lCol
If found = False Then
If IsEmpty(Cells(i, j)) Then
Cells(i, j).Delete Shift:=xlToLeft
j = j - 1
Else
found = True
End If
Else
If IsEmpty(Cells(i, j)) Then _
Cells(i, j) = Cells(i, j).Offset(0, -1)
End If
Next j
Next i
End Sub


Jason Hall wrote:
I have the following Excel table:


x = blank cells


A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S


I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:


A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S


Worked 100% perfect for me and produced the exact diagram you
provided. What version of Excel are you running? Send me your
spreadsheet to the e-mail in my profile.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Hierarchy Macro

Email sent. I am using 2007

"JW" wrote:

On Oct 25, 4:54 pm, Jason Hall
wrote:
I am sorry but, that macro didn't work at all. It pulled information from
incorrect cells and didn't match the diagram I provided.

Thanks though

"JW" wrote:
One Way. This will identify the last used row and last used column in
your spreadsheet and cycle through til complete. If you want it to
cycle through different columns/rows, just change the values assigned
to the variables as needed.
Sub likeThis()
Dim sRow As Long, lRow As Long
Dim sCol As Integer, lCol As Integer
Dim found As Boolean
sRow = 1
sCol = 1
lRow = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
lCol = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
For i = sRow To lRow
found = False
For j = sCol To lCol
If found = False Then
If IsEmpty(Cells(i, j)) Then
Cells(i, j).Delete Shift:=xlToLeft
j = j - 1
Else
found = True
End If
Else
If IsEmpty(Cells(i, j)) Then _
Cells(i, j) = Cells(i, j).Offset(0, -1)
End If
Next j
Next i
End Sub


Jason Hall wrote:
I have the following Excel table:


x = blank cells


A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S


I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:


A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S


Worked 100% perfect for me and produced the exact diagram you
provided. What version of Excel are you running? Send me your
spreadsheet to the e-mail in my profile.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Hierarchy Macro

Try the following code. It assumes that your range is named "TheGrid".

Sub FillGrid()

Dim FirstCell As Range
Dim EndCell As Range

Dim FirstCol As Long
Dim LastCol As Long

Dim FirstRow As Long
Dim LastRow As Long

Dim RowNdx As Long
Dim ColNdx As Long

Dim DestCell As Range
Dim FillValue As Variant
Dim CopyRng As Range
Dim FillStart As Long
Dim FillLen As Long

With Range("TheGrid")
FirstRow = .Cells(1, 1).Row
LastRow = .Cells(.Cells.Count).Row
FirstCol = .Cells(1, 1).Column
LastCol = .Cells(.Cells.Count).Column
End With
For RowNdx = FirstRow To LastRow
ColNdx = FirstCol
If Cells(RowNdx, FirstCol).Value = vbNullString Then
Do Until (Cells(RowNdx, ColNdx) < vbNullString) Or (ColNdx =
LastCol)
ColNdx = ColNdx + 1
Loop
Set FirstCell = Cells(RowNdx, ColNdx)

If FirstCell.Value < vbNullString Then
Set DestCell = Cells(RowNdx, FirstCol)
Cells(RowNdx, FirstCell.Column).Resize(1, LastCol -
FirstCell.Column + 1).Copy Destination:=DestCell
FillValue = Cells(RowNdx, LastCol)
FillStart = FirstCol + (LastCol - FirstCell.Column)
FillLen = LastCol - FillStart + 1
Cells(RowNdx, FillStart).Resize(1, FillLen).FillRight

End If
End If
Next RowNdx

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Jason Hall" wrote in message
...
I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Hierarchy Macro

Thanks!!

"Chip Pearson" wrote:

Try the following code. It assumes that your range is named "TheGrid".

Sub FillGrid()

Dim FirstCell As Range
Dim EndCell As Range

Dim FirstCol As Long
Dim LastCol As Long

Dim FirstRow As Long
Dim LastRow As Long

Dim RowNdx As Long
Dim ColNdx As Long

Dim DestCell As Range
Dim FillValue As Variant
Dim CopyRng As Range
Dim FillStart As Long
Dim FillLen As Long

With Range("TheGrid")
FirstRow = .Cells(1, 1).Row
LastRow = .Cells(.Cells.Count).Row
FirstCol = .Cells(1, 1).Column
LastCol = .Cells(.Cells.Count).Column
End With
For RowNdx = FirstRow To LastRow
ColNdx = FirstCol
If Cells(RowNdx, FirstCol).Value = vbNullString Then
Do Until (Cells(RowNdx, ColNdx) < vbNullString) Or (ColNdx =
LastCol)
ColNdx = ColNdx + 1
Loop
Set FirstCell = Cells(RowNdx, ColNdx)

If FirstCell.Value < vbNullString Then
Set DestCell = Cells(RowNdx, FirstCol)
Cells(RowNdx, FirstCell.Column).Resize(1, LastCol -
FirstCell.Column + 1).Copy Destination:=DestCell
FillValue = Cells(RowNdx, LastCol)
FillStart = FirstCol + (LastCol - FirstCell.Column)
FillLen = LastCol - FillStart + 1
Cells(RowNdx, FillStart).Resize(1, FillLen).FillRight

End If
End If
Next RowNdx

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Jason Hall" wrote in message
...
I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Hierarchy Macro

On Oct 25, 7:10 pm, Jason Hall
wrote:
Thanks!!

"Chip Pearson" wrote:
Try the following code. It assumes that your range is named "TheGrid".


Sub FillGrid()


Dim FirstCell As Range
Dim EndCell As Range


Dim FirstCol As Long
Dim LastCol As Long


Dim FirstRow As Long
Dim LastRow As Long


Dim RowNdx As Long
Dim ColNdx As Long


Dim DestCell As Range
Dim FillValue As Variant
Dim CopyRng As Range
Dim FillStart As Long
Dim FillLen As Long


With Range("TheGrid")
FirstRow = .Cells(1, 1).Row
LastRow = .Cells(.Cells.Count).Row
FirstCol = .Cells(1, 1).Column
LastCol = .Cells(.Cells.Count).Column
End With
For RowNdx = FirstRow To LastRow
ColNdx = FirstCol
If Cells(RowNdx, FirstCol).Value = vbNullString Then
Do Until (Cells(RowNdx, ColNdx) < vbNullString) Or (ColNdx =
LastCol)
ColNdx = ColNdx + 1
Loop
Set FirstCell = Cells(RowNdx, ColNdx)


If FirstCell.Value < vbNullString Then
Set DestCell = Cells(RowNdx, FirstCol)
Cells(RowNdx, FirstCell.Column).Resize(1, LastCol -
FirstCell.Column + 1).Copy Destination:=DestCell
FillValue = Cells(RowNdx, LastCol)
FillStart = FirstCol + (LastCol - FirstCell.Column)
FillLen = LastCol - FillStart + 1
Cells(RowNdx, FillStart).Resize(1, FillLen).FillRight


End If
End If
Next RowNdx


End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Jason Hall" wrote in message
...
I have the following Excel table:


x = blank cells


A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S


I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:


A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S


Looks like Chip got you covered. But thought I would post this up
anyhow. Based on the sheet you sent me, the cells may look empty, but
they aren't. So, I just changed the IsEmpty check to a Len check and
it works fine. Keep in mind that this is in Excel 2003, though it
should work fine in 2007.
Sub likeThis()
Dim sRow As Long, lRow As Long
Dim sCol As Integer, lCol As Integer
Dim found As Boolean
sRow = 2
sCol = 1
lRow = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
lCol = Cells.Find(what:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
For i = sRow To lRow
found = False
For j = sCol To lCol
If found = False Then
If Len(Cells(i, j)) = 0 Then
Cells(i, j).Delete Shift:=xlToLeft
j = j - 1
Else
found = True
End If
Else
If Len(Cells(i, j)) = 0 Then _
Cells(i, j) = Cells(i, j).Offset(0, -1)
End If
Next j
Next i
End Sub

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Hierarchy Macro

If the cells to the right of your table is clear, maybe:

Sub Demo()
With [A1:H8]
.SpecialCells(xlCellTypeBlanks).Delete (xlToLeft)
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=RC[-1]"
.Value = .Value
End With
End Sub

--
Dana DeLouis
Windows XP & Excel 2007


"Jason Hall" wrote in message
...
I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Hierarchy Macro

Now that's slick. I wish I had thought of that.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Dana DeLouis" wrote in message
...
If the cells to the right of your table is clear, maybe:

Sub Demo()
With [A1:H8]
.SpecialCells(xlCellTypeBlanks).Delete (xlToLeft)
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=RC[-1]"
.Value = .Value
End With
End Sub

--
Dana DeLouis
Windows XP & Excel 2007


"Jason Hall" wrote in message
...
I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S






  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Hierarchy Macro

Chip, I agree. That is some really slick code Dana.

Chip Pearson wrote:
Now that's slick. I wish I had thought of that.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Dana DeLouis" wrote in message
...
If the cells to the right of your table is clear, maybe:

Sub Demo()
With [A1:H8]
.SpecialCells(xlCellTypeBlanks).Delete (xlToLeft)
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=RC[-1]"
.Value = .Value
End With
End Sub

--
Dana DeLouis
Windows XP & Excel 2007


"Jason Hall" wrote in message
...
I have the following Excel table:

x = blank cells

A B C D E F G H
1 x x x x x x M R
2 x x x x x M R T
3 x x x x M R T S
4 x x x M R T S Y
5 x x M R T S Y N
6 x M R T S Y N Q
7 M R T S Y N Q W
8 x x x x M R T S

I want to have Excel see the blanks (if there is one) and place the M in
column A and any cells up to column H to be back filled with the existing
data. Please see what I want the above table to look like after macro:

A B C D E F G H
1 M R R R R R R R
2 M R T T T T T T
3 M R T S S S S S
4 M R T S Y Y Y Y
5 M R T S Y N N N
6 M R T S Y N Q Q
7 M R T S Y N Q W
8 M R T S S S S S




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hierarchy table Derrick Excel Discussion (Misc queries) 1 October 31st 08 01:53 AM
Supervisor Hierarchy Steve C Excel Discussion (Misc queries) 0 July 17th 08 03:34 AM
Class Hierarchy in VBA [email protected] Excel Programming 8 March 30th 07 12:32 PM
Sum in hierarchy hideki[_26_] Excel Programming 3 February 23rd 06 06:24 PM
SUMPRODUCT - HIERARCHY Matt Brown via OfficeKB.com Excel Worksheet Functions 5 November 6th 04 03:54 AM


All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"