VBA Help - Check if multiple String Variables are Blank

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello All,

I have a small script that takes values from one sheet and populates other tabs based on specific criteria.

I have a small declaration of variables that I am trying to validate that there are values within the variables, if not I want to change the variables to "N/A" as the output. Not sure how to write a script like thought without repeating a IF/Then statement for each of my variables.

List of Variables (Small Sample List):
ProjectName = .Cells(r, 1).Value
ProjectDesc = .Cells(r, 2).Value
Status = .Cells(r, 3).Value
Time = .Cells(r, 4).Value

This is how I did it but there has to be a better way -

VBA Code:
if ProjectName = vbnullstring then Projectname = "N/A"

And I just repeated this 10 times for all the other variables. Any help is appreciated.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
run it thru a function:

Code:
Public Sub RunApp()
ProjectName = Assign1(.Cells(r, 1).Value)
ProjectDesc = Assign1(.Cells(r, 2).Value)
Status = Assign1(.Cells(r, 3).Value)
Time = Assign1(.Cells(r, 4).Value)

End Sub


Public function Assign1(ByVal pvVal)
If (pvVal) = "" Or IsNull(pvVal) Then
   Assign1 = "N/A"
Else
   Assign1 = pvVal
End If
End function
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top