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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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