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


Hi all

I am complete novice when it come to macros in excel but I am trying t
learn! I have been trying to get a loop macro to work to delete cell
which are blank. But it just keeps deleting and does not stop whe
there is some content in the cell.
HEre is the code! What am I doing wrong?

Sub Macro2()

Do
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Loop Until a1 0

End Su

--
jim2

-----------------------------------------------------------------------
jim27's Profile: http://www.excelforum.com/member.php...fo&userid=1537
View this thread: http://www.excelforum.com/showthread.php?threadid=26996

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default simple loop macro

You need a few things

- identify the last cell
- keep a counter/pointer, so that you know where you are
- work bottom up (when deleting)
- iden tify a key column (I use A in the example)

Sub Macro2()
Dim cRows As Long
Dim i As Long

'find the row number of the last row that has data in it in
'column A
cRows = Cells(Rows.Count,"A").End(xlUp).Row
'now run a loop from that line back to row 1
For i = cRows To 1 Step -1
'check if the cell for this row in column is empty
If Cells(i,"A").Value = "" Then
Cells(i,"A").Delete Shift:=xlUp
End If
Next

End Sub


--

HTH

RP

"jim27" wrote in message
...

Hi all

I am complete novice when it come to macros in excel but I am trying to
learn! I have been trying to get a loop macro to work to delete cells
which are blank. But it just keeps deleting and does not stop when
there is some content in the cell.
HEre is the code! What am I doing wrong?

Sub Macro2()

Do
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Loop Until a1 0

End Sub


--
jim27


------------------------------------------------------------------------
jim27's Profile:

http://www.excelforum.com/member.php...o&userid=15379
View this thread: http://www.excelforum.com/showthread...hreadid=269967



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default simple loop macro

Just to add some explanation to you current code.
a1 doesn't refer to Range("A1")

Sub Macro2()

Do While isempty(Range("a1"))
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Loop

End Sub

--
Regards,
Tom Ogilvy


"jim27" wrote in message
...

Hi all

I am complete novice when it come to macros in excel but I am trying to
learn! I have been trying to get a loop macro to work to delete cells
which are blank. But it just keeps deleting and does not stop when
there is some content in the cell.
HEre is the code! What am I doing wrong?

Sub Macro2()

Do
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Loop Until a1 0

End Sub


--
jim27


------------------------------------------------------------------------
jim27's Profile:

http://www.excelforum.com/member.php...o&userid=15379
View this thread: http://www.excelforum.com/showthread...hreadid=269967



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
simple loop needed please Alan Excel Discussion (Misc queries) 1 May 5th 10 06:33 PM
I need a simple loop with a 4+ row added in. pgarcia Excel Discussion (Misc queries) 5 July 19th 07 07:42 PM
how can i loop a macro Remote help Excel Discussion (Misc queries) 1 July 21st 05 02:57 AM
Probably missing something simple in loop macro...Please help Jules[_6_] Excel Programming 3 April 15th 04 05:16 AM
Simple problem refering to variable in For ... Next loop ... Chris Excel Programming 1 July 15th 03 01:00 AM


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