0

I need a macro to look at 6 specific ranges:

("F15:F4999") ("H15:H4999") ("J15:J4999") ("L15:L4999") ("N15:N4999") ("P15:P4999")

If one or more of these ranges is blank, I need the macro to enter "No Data" in the first cell of the blank range(s) (i.e. in F15). The ranges contain various types of data to include text, dollar values, dates, and percentages.

This macro will be part of it's own module, and will be called at the end of another macro.

I have tried using the COUNTA function, but get hung up due to type mismatch errors. The following works, but only for the first blank range each time I run it. (i.e. if column F is blank, it will enter "No Data", but will not continue on and enter "No Data in blank columns that follow)

Sub FillFetchDataBlanks()

Application.ScreenUpdating = False
Application.EnableEvents = False

Sheets("Graph Data").Select

If Application.WorksheetFunction.CountA(Range("F15:F4999")) <= 0 Then
[F15] = "No Data"

ElseIf Application.WorksheetFunction.CountA(Range("H15:H4999")) <= 0 Then
[H15] = "No Data"

ElseIf Application.WorksheetFunction.CountA(Range("J15:J4999")) <= 0 Then
[J15] = "No Data"

ElseIf Application.WorksheetFunction.CountA(Range("L15:L4999")) <= 0 Then
[L15] = "No Data"

ElseIf Application.WorksheetFunction.CountA(Range("N15:N4999")) <= 0 Then
[N15] = "No Data"

ElseIf Application.WorksheetFunction.CountA(Range("P15:P4999")) <= 0 Then
[P15] = "No Data"

Else

On Error Resume Next


End If

[b15].Select

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Any help and/or advice is appreciated!

Thank you,

John

1
  • use separate Ifs i.e do not combine them using elsif Aug 18, 2014 at 18:26

1 Answer 1

0

You have to use separate Ifs i.e do not combine them using ElseIf.

Try this

With Application.WorksheetFunction
    If .CountA(Range("F15:F4999")) <= 0 Then [F15] = "No Data"
    If .CountA(Range("H15:H4999")) <= 0 Then [H15] = "No Data"
    If .CountA(Range("J15:J4999")) <= 0 Then [J15] = "No Data"
    If .CountA(Range("L15:L4999")) <= 0 Then [L15] = "No Data"
    If .CountA(Range("N15:N4999")) <= 0 Then [N15] = "No Data"
    If .CountA(Range("P15:P4999")) <= 0 Then [P15] = "No Data"
End With

This way you also don't need an Else and End If

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.