View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] meh2030@gmail.com is offline
external usenet poster
 
Posts: 135
Default skip to next part of program if a cell blank

On Feb 20, 11:18*am, SteveC wrote:
Hello, here is my code. *How do I modify it so that if a range is blank, it
will move on to the next step. *For example, if the cells in A2:A1000 are
blank, how do I get the program to move on to Step 2? *And if B2:B1000 are
blank, how do I get it to move on to step 3? and etc...

Sub Update_Performance()

'Step 1
* * Sheets("Input").Select
* * Range("A2:A1000").Select
* * Selection.Copy
* * Sheets("HL").Select
* * Range("D2").Select
* * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
* * * * :=False, Transpose:=False

'Step 2
* * Sheets("Input").Select
* * Range("b2:b1000").Select
* * Selection.Copy
* * Sheets("HL2").Select
* * Range("D2").Select
* * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
* * * * :=False, Transpose:=False

'Step 3
* * Sheets("Input").Select
* * Range("c2:c1000").Select
* * Selection.Copy
* * Sheets("HL3").Select
* * Range("D2").Select
* * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
* * * * :=False, Transpose:=False

'Step etc... to Step 70

end sub


Steve,

You can try something like what is listed below. It will benefit you
to look into using a For loop. If I have more time later, I'll send
an example of a For loop for your situation.

Sub TestIt()
Dim wksCopySheet As Worksheet
Dim wksPasteSheet As Worksheet
Dim rngCopy As Range
Dim rngPaste As Range
Dim strCellOutput As String

'set constant variables
Set wksCopySheet = Worksheets("Input")
strCellOutput = "D2"

'Step 1
Set rngCopy = wksCopySheet.Range("A2:A1000")
Set wksPasteSheet = Worksheets("HL")
Set rngPaste = wksPasteSheet.Range(strCellOutput)

If Application.WorksheetFunction.CountA(rngCopy) < 0 Then
rngCopy.Copy
rngPaste.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End If

'Step 2
Set rngCopy = wksCopySheet.Range("B2:B1000")
Set wksPasteSheet = Worksheets("HL2")
Set rngPaste = wksPasteSheet.Range(strCellOutput)

If Application.WorksheetFunction.CountA(rngCopy) < 0 Then
rngCopy.Copy
rngPaste.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End If

'Other Steps

End Sub

Matt