Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Pasting Values Problem - sorting feature messed up

Screwed up the step. Use this one.

Sub delBlanks()
Dim i as Long
For i = 25 To 2 Step -1
If WorksheetFunction.CountA(Range(i & ":" & i) = 0 Then
Rows(i).Delete
End If
Next
End Sub



"JLGWhiz" wrote:

It appears that you are copying the entire range, including the rows that
have no data displayed, in block and then using paste special to paste only
the rows with values. If you are only working with the 24 rows pasted in
rows 2 - 25 then maybe you could use this little macro to get rid of the
blank rows.

Sub delBlanks()
Dim i as Long
For i = 25 To 2 Step -2
If WorksheetFunction.CountA(Range(i & ":" & i) = 0 Then
Rows(i).Delete
End If
Next
End Sub

This will start on row 25 and work its way to row 2. Since you used
PasteSpecial to paste only values in this range, the CountA should identify
all of the rows that are blank.

"Munchkin" wrote:

Here's my VBA code..but got to be honest, I'm only self-taught @ this stuff.
Not nearly the expert that so many other here are.


ActiveSheet.Unprotect
Sheets("Payment History").Select
ActiveSheet.Unprotect
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveWindow.SmallScroll Down:=-9
Rows("2:25").Select
Selection.Insert Shift:=xlDown
Range("A2").Select
Sheets("CR Template").Select
Range("C21:I41").Select
Application.Goto Reference:="NewRecord"
Selection.Copy
Sheets("Payment History").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Cells.Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns("B:B").Select
Selection.NumberFormat = "m/d/yy;@"
Cells.Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A2").Select
Sheets("CR Template").Select
Range("D21").Select
ActiveSheet.Protect
End Sub


"JLGWhiz" wrote:

Yes it will skip the cells where the formula value equates to "". From your
description and since you chose not to post the code you are using, I assumed
that the formulas in the cells are constructed so that if there is no data to
calculte then the value = "" to avoid error flags or zeros from appearing in
the cell.

"Munchkin" wrote:

So if you copy & skip blank rows it looks for values only in each cell &
ignores the formula?

"JLGWhiz" wrote:

You should post the code you are currently using. However, it appears that
the problem is in how you copy the data from the source sheet. You can use
an If...Then statement to ignore the blank rows for copying. For example:

If Range("A1").Value < "" Then
Range("A1").EntireRow.Copy Sheets(2). _
Range("A" & Range(A65536").End(xlUP).Row)
End If

The above code would only copy the row if there is data in it. Otherwise it
is ignored.

"Munchkin" wrote:

This is complicated to explain - I'll do my best.

I have a macro that copies rows 10-34 from one worksheet & puts them on a
2nd worksheet. Colums A-C of each row contain a formulas that either copies
data from another cell or is left blank. If these cells are blank it means
nothing is entered on any cell of the rows. My macro copies each row anyway,
but only pastes the values onto another worksheet. (There's a reason for my
method, but the explanation would be to lengthy)

The macro works fine at moving the data, but when I try to go in & sort the
copied data I wind up with blank rows at the top. These are obviously the
copied rows that had formulas, but no text - since I pasted the values
nothing is shown in any the blank row cells - no formula or text - so what is
the sorting feature picking up?

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
Sorting with expanding a section feature DMS @ CFH Excel Discussion (Misc queries) 1 August 7th 09 08:01 PM
How to use VBA to automate sorting, cutting & pasting in Excel? FredB Excel Programming 2 September 5th 07 04:22 PM
Linking messed up when Sorting Jugglertwo Excel Discussion (Misc queries) 1 March 17th 06 08:23 PM
Date(Y,M,D) 'feature' or problem? Jon McP Excel Worksheet Functions 10 November 16th 05 05:41 PM
Excel 2000 VBA problem -- sorting values in subtotaled column Pemily Excel Programming 0 April 2nd 04 03:36 PM


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