Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Move non date/add blank row

How can I programmically write, if a number is found in column 1 (A) that is
not a date, move over two columns and drop in column 3 (C).

Then the next step after looping the above is to insert a blank row above
each date found in column 1 (A) for all dates found.

Thanks.

Annette


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Move non date/add blank row

One way:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim myInsertRng As Range
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))

For Each myCell In myRng.Cells
With myCell
If IsNumeric(.Value) Then
.Offset(0, 2).Value = .Value
.ClearContents
ElseIf IsDate(.Value) Then
If myInsertRng Is Nothing Then
Set myInsertRng = .Cells
Else
Set myInsertRng = Union(.Cells, myInsertRng)
End If
End If
End With
Next myCell
If myInsertRng Is Nothing Then
'do nothing
Else
myInsertRng.EntireRow.Insert
End If
End With

End Sub

But you may want to reconsider inserting that row. I find just making the
rowheight twice as big looks just as nice and it makes subsequent processing a
lot easier.

I'd do it this way:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim myInsertRng As Range

Dim wks As Worksheet

Set wks = ActiveSheet

With wks
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))

For Each myCell In myRng.Cells
With myCell
If IsNumeric(.Value) Then
.Offset(0, 2).Value = .Value
.ClearContents
ElseIf IsDate(.Value) Then
.RowHeight = .RowHeight * 2
End If
End With
Next myCell
End With

End Sub



Annette wrote:

How can I programmically write, if a number is found in column 1 (A) that is
not a date, move over two columns and drop in column 3 (C).

Then the next step after looping the above is to insert a blank row above
each date found in column 1 (A) for all dates found.

Thanks.

Annette


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Move non date/add blank row

Dave, the first part is great and is going to be used. I pulled off the
second part because we changed in the middle of the game and decided we
needed to delete all the blank rows left behind that contained no data. I
found a code in the newgroup that will satisfy the 'delete rows' written by
a fellow, Ron de Bruin. All the information I'm dealing with is mainframe
text copied over into the Excel that had to be presented to user in a
workable format. By removing all empty rows, the users can then use filter
and we felt this was a better method. Column C contains a couple rows of
text wherein the associated information found in Col A and B is only the
first line. When the text came over from the mainframe, extra lines were
added sporatically. Sometimes text from what should be column C would shift
and that's the code you wrote. Thanks for the code as it really does the
trick.
"Dave Peterson" wrote in message
...
One way:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim myInsertRng As Range
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))

For Each myCell In myRng.Cells
With myCell
If IsNumeric(.Value) Then
.Offset(0, 2).Value = .Value
.ClearContents
ElseIf IsDate(.Value) Then
If myInsertRng Is Nothing Then
Set myInsertRng = .Cells
Else
Set myInsertRng = Union(.Cells, myInsertRng)
End If
End If
End With
Next myCell
If myInsertRng Is Nothing Then
'do nothing
Else
myInsertRng.EntireRow.Insert
End If
End With

End Sub

But you may want to reconsider inserting that row. I find just making the
rowheight twice as big looks just as nice and it makes subsequent

processing a
lot easier.

I'd do it this way:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim myInsertRng As Range

Dim wks As Worksheet

Set wks = ActiveSheet

With wks
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))

For Each myCell In myRng.Cells
With myCell
If IsNumeric(.Value) Then
.Offset(0, 2).Value = .Value
.ClearContents
ElseIf IsDate(.Value) Then
.RowHeight = .RowHeight * 2
End If
End With
Next myCell
End With

End Sub



Annette wrote:

How can I programmically write, if a number is found in column 1 (A)

that is
not a date, move over two columns and drop in column 3 (C).

Then the next step after looping the above is to insert a blank row

above
each date found in column 1 (A) for all dates found.

Thanks.

Annette


--

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
Need macro to move to first blank cell in column Joe M. Excel Discussion (Misc queries) 6 December 16th 09 10:22 PM
move blank data reza Excel Discussion (Misc queries) 10 October 6th 09 10:49 AM
Macro to delete blank rows and move data/info samoan Excel Discussion (Misc queries) 3 September 19th 08 04:50 PM
Remove Civic numbers in Street Address, move to previous blank cell Canuck Excel Worksheet Functions 1 October 12th 06 03:31 PM
How do I make a blank cell with a date format blank? Pivot Table/Query Excel Worksheet Functions 6 June 14th 05 11:19 PM


All times are GMT +1. The time now is 03:44 PM.

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"