Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default help with "Goto" command

I have most of a macro but am having trouble with the goto command. I want to
use a specific reference in sheet 2 (it is the result of a formula that has
been copied as text to an adjacent column). The specific reference points to
a cell in sheet 1 that I am going to delete.

It is the "Application.Goto reference" line in the Do While...Loop I am
having trouble with - unless someone can think of a better way of getting the
result

How can I use the reference in sheet 2 in my macro without having to
actually type the text? Because typing it in the macro will "fix it" and make
it unchangeable which therefore will not felxible enough to use the
references below it.

Here is a small sample of the list of references I am trying to use in the
macro:
First row is the heading of the list and they are all in Column D of sheet 2:

Current Mail List
'Sheet 1'!$Q$5447
'Sheet 1'!$Q$12
'Sheet 1'!$Q$4
'Sheet 1'!$Q$16
'Sheet 1'!$Q$9


Here is my macro so far:

Sub cleanup()
'
' cleanup Macro
'
' Keyboard Shortcut: Ctrl+q
'
' select and copy column C i.e. the reference formulas
Columns("C:C").Select
Selection.Copy
'
' paste col C as Values in column D in the same order, do not delete col C
Columns("D:D").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'
' sort all by the formula in col E to move all #N/A (i.e. data in
col A
' not existent in sheet 1) to the bottom of the sheet so the Do
While...Loop
' below runs correctly
Columns("A:E").Select
Selection.Sort Key1:=Range("E2"), Order1:=xlDescending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

' starting at row 2 col D, loop until there is a blank row in col D
x = 2
Do While Cells(x, 4).Value < ""
'
' using the reference in each row in col D of sheet 2, go to that
' reference (in sheet 1) and delete the cell contents
Application.Goto reference:="'Sheet 1'!R5447C17"
Selection.ClearContents
'
x = x + 1
Loop

End Sub



--
Thank you in advance for your assistance.
James
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default help with "Goto" command

Instead of goto just use range

RowCount = 2
Do While Cells(RowCount, "D").Value < ""
'
' using the reference in each row in col D of sheet 2, go to that
' reference (in sheet 1) and delete the cell contents
'
Range(Cells(RowCount,"D")).ClearContents
RowCount = Rowcount + 1
Loop


"James" wrote:

I have most of a macro but am having trouble with the goto command. I want to
use a specific reference in sheet 2 (it is the result of a formula that has
been copied as text to an adjacent column). The specific reference points to
a cell in sheet 1 that I am going to delete.

It is the "Application.Goto reference" line in the Do While...Loop I am
having trouble with - unless someone can think of a better way of getting the
result

How can I use the reference in sheet 2 in my macro without having to
actually type the text? Because typing it in the macro will "fix it" and make
it unchangeable which therefore will not felxible enough to use the
references below it.

Here is a small sample of the list of references I am trying to use in the
macro:
First row is the heading of the list and they are all in Column D of sheet 2:

Current Mail List
'Sheet 1'!$Q$5447
'Sheet 1'!$Q$12
'Sheet 1'!$Q$4
'Sheet 1'!$Q$16
'Sheet 1'!$Q$9


Here is my macro so far:

Sub cleanup()
'
' cleanup Macro
'
' Keyboard Shortcut: Ctrl+q
'
' select and copy column C i.e. the reference formulas
Columns("C:C").Select
Selection.Copy
'
' paste col C as Values in column D in the same order, do not delete col C
Columns("D:D").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'
' sort all by the formula in col E to move all #N/A (i.e. data in
col A
' not existent in sheet 1) to the bottom of the sheet so the Do
While...Loop
' below runs correctly
Columns("A:E").Select
Selection.Sort Key1:=Range("E2"), Order1:=xlDescending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

' starting at row 2 col D, loop until there is a blank row in col D
x = 2
Do While Cells(x, 4).Value < ""
'
' using the reference in each row in col D of sheet 2, go to that
' reference (in sheet 1) and delete the cell contents
Application.Goto reference:="'Sheet 1'!R5447C17"
Selection.ClearContents
'
x = x + 1
Loop

End Sub



--
Thank you in advance for your assistance.
James

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default help with "Goto" command

thank you Joel - you are a master. Great solution - appreciate your response

Cheers
--
Thank you in advance for your assistance.
James


"Joel" wrote:

Instead of goto just use range

RowCount = 2
Do While Cells(RowCount, "D").Value < ""
'
' using the reference in each row in col D of sheet 2, go to that
' reference (in sheet 1) and delete the cell contents
'
Range(Cells(RowCount,"D")).ClearContents
RowCount = Rowcount + 1
Loop


"James" wrote:

I have most of a macro but am having trouble with the goto command. I want to
use a specific reference in sheet 2 (it is the result of a formula that has
been copied as text to an adjacent column). The specific reference points to
a cell in sheet 1 that I am going to delete.

It is the "Application.Goto reference" line in the Do While...Loop I am
having trouble with - unless someone can think of a better way of getting the
result

How can I use the reference in sheet 2 in my macro without having to
actually type the text? Because typing it in the macro will "fix it" and make
it unchangeable which therefore will not felxible enough to use the
references below it.

Here is a small sample of the list of references I am trying to use in the
macro:
First row is the heading of the list and they are all in Column D of sheet 2:

Current Mail List
'Sheet 1'!$Q$5447
'Sheet 1'!$Q$12
'Sheet 1'!$Q$4
'Sheet 1'!$Q$16
'Sheet 1'!$Q$9


Here is my macro so far:

Sub cleanup()
'
' cleanup Macro
'
' Keyboard Shortcut: Ctrl+q
'
' select and copy column C i.e. the reference formulas
Columns("C:C").Select
Selection.Copy
'
' paste col C as Values in column D in the same order, do not delete col C
Columns("D:D").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'
' sort all by the formula in col E to move all #N/A (i.e. data in
col A
' not existent in sheet 1) to the bottom of the sheet so the Do
While...Loop
' below runs correctly
Columns("A:E").Select
Selection.Sort Key1:=Range("E2"), Order1:=xlDescending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

' starting at row 2 col D, loop until there is a blank row in col D
x = 2
Do While Cells(x, 4).Value < ""
'
' using the reference in each row in col D of sheet 2, go to that
' reference (in sheet 1) and delete the cell contents
Application.Goto reference:="'Sheet 1'!R5447C17"
Selection.ClearContents
'
x = x + 1
Loop

End Sub



--
Thank you in advance for your assistance.
James

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
ie Command to Wait for "File Download" and "Save As" windows [email protected] Excel Programming 11 April 24th 08 11:20 AM
command button and the "enter" and "tab" keys dr chuck Excel Programming 10 September 11th 06 12:09 AM
inserting a conditional "go to" command on a excel "if" function velasques Excel Worksheet Functions 5 March 10th 06 08:16 PM
Is there a "replace" or "Substitute" command in Excel's VB? [email protected] Excel Programming 2 December 5th 03 07:56 AM


All times are GMT +1. The time now is 08:50 AM.

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

About Us

"It's about Microsoft Excel"