Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default How do I stop this macro?

The macro below transposes data in a variable sized table on a worksheet so
in this case the macro would add 67, 28 and 37 to the top row, 47 and 89 to
the second row and 58 to the third row.

100
67 100
28 47 100
37 89 58 100

My problem is it doesn't stop when the macro reaches the cell in the bottom
right corner of the range.

You'll see I've tried to use a Do Loop solution which I've placed in various
sections of the code without success.

-------------------------

Sub TranposeData()

Dim lastrow As Long
Dim R As Long, C As Integer
Dim rng As Range

ActiveCell.Offset(1, 1).Activate

Set rng = ActiveCell

lastrow = ActiveCell.End(xlDown).Row + 1
Do Until ActiveCell.Offset(1, 1) = Empty

For R = rng(1).Row To lastrow
C = Cells(R, Columns.Count).End(xlToLeft).Column

Range(Cells(R + 1, C), Cells(lastrow - 1, C)).Copy
Cells(R, C + 1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:=False, Transpose:=True

Next R
Loop


Application.CutCopyMode = False

End Sub


----------

I'd be grateful for some help on how to make this run correctly.

Thanks a lot

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How do I stop this macro?

How about something like:

Option Explicit
Sub testme()
Dim iRow As Long
Dim iCol As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iCol = FirstRow To LastRow
For iRow = iCol + 1 To LastRow
.Cells(iCol, iRow).Value = .Cells(iRow, iCol).Value
Next iRow
Next iCol
End With

End Sub

It just plops the value from cell(x,y) into cell(y,x).



nospaminlich wrote:

The macro below transposes data in a variable sized table on a worksheet so
in this case the macro would add 67, 28 and 37 to the top row, 47 and 89 to
the second row and 58 to the third row.

100
67 100
28 47 100
37 89 58 100

My problem is it doesn't stop when the macro reaches the cell in the bottom
right corner of the range.

You'll see I've tried to use a Do Loop solution which I've placed in various
sections of the code without success.

-------------------------

Sub TranposeData()

Dim lastrow As Long
Dim R As Long, C As Integer
Dim rng As Range

ActiveCell.Offset(1, 1).Activate

Set rng = ActiveCell

lastrow = ActiveCell.End(xlDown).Row + 1
Do Until ActiveCell.Offset(1, 1) = Empty

For R = rng(1).Row To lastrow
C = Cells(R, Columns.Count).End(xlToLeft).Column

Range(Cells(R + 1, C), Cells(lastrow - 1, C)).Copy
Cells(R, C + 1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:=False, Transpose:=True

Next R
Loop


Application.CutCopyMode = False

End Sub

----------

I'd be grateful for some help on how to make this run correctly.

Thanks a lot


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default How do I stop this macro?

Thanks a lot.

I've tried this but it seems to start at cell A1 and keep going rather than
starting at any point on a sheet and stopping at the end of that range of
cells e.g. the bottom right of the table.

The code in my original post Sub TransposeData() below was designed to run
from the cell one up and to the left of a table (where a shape would be to
invoke the macro) and stop when it reached the bottom right hand cell in that
range.

My code got the data transposed albeit in a different way than yours but I
still have the problem of adding something that tells the macro when to halt
as that's the bit that doesn't work.

I've spent hours trying variations on a theme here but as you can probably
tell I'm well beyond my level of expertise so really need more help to get
the macro to run only in the area of a single range.

Thanks again

"Dave Peterson" wrote:

How about something like:

Option Explicit
Sub testme()
Dim iRow As Long
Dim iCol As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iCol = FirstRow To LastRow
For iRow = iCol + 1 To LastRow
.Cells(iCol, iRow).Value = .Cells(iRow, iCol).Value
Next iRow
Next iCol
End With

End Sub

It just plops the value from cell(x,y) into cell(y,x).


Dave Peterson



nospaminlich wrote:

The macro below transposes data in a variable sized table on a worksheet so
in this case the macro would add 67, 28 and 37 to the top row, 47 and 89 to
the second row and 58 to the third row.

100
67 100
28 47 100
37 89 58 100

My problem is it doesn't stop when the macro reaches the cell in the bottom
right corner of the range.

You'll see I've tried to use a Do Loop solution which I've placed in various
sections of the code without success.

-------------------------

Sub TranposeData()

Dim lastrow As Long
Dim R As Long, C As Integer
Dim rng As Range

ActiveCell.Offset(1, 1).Activate

Set rng = ActiveCell

lastrow = ActiveCell.End(xlDown).Row + 1
Do Until ActiveCell.Offset(1, 1) = Empty

For R = rng(1).Row To lastrow
C = Cells(R, Columns.Count).End(xlToLeft).Column

Range(Cells(R + 1, C), Cells(lastrow - 1, C)).Copy
Cells(R, C + 1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:=False, Transpose:=True

Next R
Loop


Application.CutCopyMode = False

End Sub

----------

I'd be grateful for some help on how to make this run correctly.

Thanks a lot


--


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How do I stop this macro?

You can select the first column in the table and then run this:

Option Explicit
Sub testme()
Dim iRow As Long
Dim iCol As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 1
LastRow = Selection.Rows.Count

For iCol = FirstRow To LastRow
For iRow = iCol + 1 To LastRow
Selection.Cells(iCol, iRow).Value _
= Selection.Cells(iRow, iCol).Value
Next iRow
Next iCol
End With

End Sub


nospaminlich wrote:

Thanks a lot.

I've tried this but it seems to start at cell A1 and keep going rather than
starting at any point on a sheet and stopping at the end of that range of
cells e.g. the bottom right of the table.

The code in my original post Sub TransposeData() below was designed to run
from the cell one up and to the left of a table (where a shape would be to
invoke the macro) and stop when it reached the bottom right hand cell in that
range.

My code got the data transposed albeit in a different way than yours but I
still have the problem of adding something that tells the macro when to halt
as that's the bit that doesn't work.

I've spent hours trying variations on a theme here but as you can probably
tell I'm well beyond my level of expertise so really need more help to get
the macro to run only in the area of a single range.

Thanks again

"Dave Peterson" wrote:

How about something like:

Option Explicit
Sub testme()
Dim iRow As Long
Dim iCol As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iCol = FirstRow To LastRow
For iRow = iCol + 1 To LastRow
.Cells(iCol, iRow).Value = .Cells(iRow, iCol).Value
Next iRow
Next iCol
End With

End Sub

It just plops the value from cell(x,y) into cell(y,x).


Dave Peterson



nospaminlich wrote:

The macro below transposes data in a variable sized table on a worksheet so
in this case the macro would add 67, 28 and 37 to the top row, 47 and 89 to
the second row and 58 to the third row.

100
67 100
28 47 100
37 89 58 100

My problem is it doesn't stop when the macro reaches the cell in the bottom
right corner of the range.

You'll see I've tried to use a Do Loop solution which I've placed in various
sections of the code without success.

-------------------------

Sub TranposeData()

Dim lastrow As Long
Dim R As Long, C As Integer
Dim rng As Range

ActiveCell.Offset(1, 1).Activate

Set rng = ActiveCell

lastrow = ActiveCell.End(xlDown).Row + 1
Do Until ActiveCell.Offset(1, 1) = Empty

For R = rng(1).Row To lastrow
C = Cells(R, Columns.Count).End(xlToLeft).Column

Range(Cells(R + 1, C), Cells(lastrow - 1, C)).Copy
Cells(R, C + 1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:=False, Transpose:=True

Next R
Loop


Application.CutCopyMode = False

End Sub

----------

I'd be grateful for some help on how to make this run correctly.

Thanks a lot


--


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default How do I stop this macro?

Thanks a lot for your help.

This did the job perfectly when I just ran the macro rather that using Step
mode. I don't really understand why that is but I've learnt a lesson and my
problem is solved.

Thanks again


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How do I stop this macro?

The code should have worked in step mode or via tools|macro|macros...|run.

I'm guessing the reason it failed may have been the initial selected range???

nospaminlich wrote:

Thanks a lot for your help.

This did the job perfectly when I just ran the macro rather that using Step
mode. I don't really understand why that is but I've learnt a lesson and my
problem is solved.

Thanks again


--

Dave Peterson
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
Macro to stop at a certain tab and does not go to the next one. [email protected] Excel Worksheet Functions 3 March 16th 06 01:11 AM
How do I stop a macro from running within a macro? JohnUK Excel Programming 1 June 26th 05 10:59 AM
Stop running a macro in the middle of a macro gmunro Excel Programming 3 June 9th 05 06:00 PM
Macro: With Stop it works. Without Stop it doesn't. Don Wiss Excel Programming 2 October 12th 04 10:49 AM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 03:11 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"