Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Copying values skipping blanks

I have a macro that is supposed to create an order form based on our current
inventory. I use a script that I got help on from this forum. When I run
this macro, sometimes it works, (It is supposed to copy a cell value created
from a formula and place it into another column skipping all blank cells)
Sometimes it copies the formula in the cell instead of the value.

What would I need to change to get it to copy only the VALUE to the new cell?

Macro example below:

Sub OfficeDepotDB()

Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range

With Application
CalcMode = .Calculation
..Calculation = xlCalculationManual
..ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
..DisplayPageBreaks = False
StartRow = 1
EndRow = 50

For Lrow = StartRow To EndRow Step 1

If IsError(.Cells(Lrow, "K").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "K").Value < "" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "K")
Else
Set rng = Application.Union(rng, .Cells(Lrow, "K"))
End If
End If

Next
End With

If Not rng Is Nothing Then rng.Copy Range("L3")

ActiveWindow.View = ViewMode
With Application
..ScreenUpdating = True
..Calculation = CalcMode
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying values skipping blanks

Sub OfficeDepotDB()

Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range

With Application
CalcMode = .Calculation
..Calculation = xlCalculationManual
..ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
..DisplayPageBreaks = False
StartRow = 1
EndRow = 50

For Lrow = StartRow To EndRow Step 1

If IsError(.Cells(Lrow, "K").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "K").Value < "" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "K")
Else
Set rng = Application.Union(rng, .Cells(Lrow, "K"))
End If
End If

Next
End With

If Not rng Is Nothing Then
rng.copy
Range("L3").PasteSpecial xlPasteValues
End if

ActiveWindow.View = ViewMode
With Application
..ScreenUpdating = True
..Calculation = CalcMode
End With

End Sub

--
Regards,
Tom Ogilvy

"justaguyfromky" wrote in message
...
I have a macro that is supposed to create an order form based on our
current
inventory. I use a script that I got help on from this forum. When I
run
this macro, sometimes it works, (It is supposed to copy a cell value
created
from a formula and place it into another column skipping all blank cells)
Sometimes it copies the formula in the cell instead of the value.

What would I need to change to get it to copy only the VALUE to the new
cell?

Macro example below:

Sub OfficeDepotDB()

Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 50

For Lrow = StartRow To EndRow Step 1

If IsError(.Cells(Lrow, "K").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "K").Value < "" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "K")
Else
Set rng = Application.Union(rng, .Cells(Lrow, "K"))
End If
End If

Next
End With

If Not rng Is Nothing Then rng.Copy Range("L3")

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub



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
Skipping Blanks (Again) F. Lawrence Kulchar Excel Discussion (Misc queries) 3 March 7th 08 10:43 PM
Skipping Blanks F. Lawrence Kulchar Excel Discussion (Misc queries) 1 March 7th 08 11:27 AM
Copying values but skipping empty cells Handyy Excel Worksheet Functions 1 February 9th 06 01:41 AM
Skipping blanks jmkona Excel Discussion (Misc queries) 2 August 27th 05 01:12 AM
Paste Special Skip Blanks not skipping blanks, but overwriting... gsrosin Excel Discussion (Misc queries) 0 February 22nd 05 03:33 AM


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