• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

VB Script Formula problem

Is there a way to change these so that if the Source Cell is empty that they either does nothing or places a vbNullString ? Currently it places a space when there is nothing there.

      DestSheet.Range("I10") = SourceSheet.Cells(0 + Student, 1) & " " & SourceSheet.Cells(0 + Student, 2)
      DestSheet.Range("J11") = SourceSheet.Cells(0 + Student, 2)

1 Solution
Dave BrettCommented:
You can test for a string greater than 0 characters in the source cell, ie this code will do nothing if  SourceSheet.Cells(0 + Student, 2).Value) is empty


If Len(SourceSheet.Cells(0 + Student, 2).Value) > 0 Then DestSheet.Range("J11") = SourceSheet.Cells(0 + Student, 2)

Open in new window

Rory ArchibaldCommented:
You could use:

DestSheet.Range("I10") = Trim(SourceSheet.Cells(0 + Student, 1) & " " & SourceSheet.Cells(0 + Student, 2))
LazarusAuthor Commented:
This solution works best for the script I'm working with, when using the If Len script is tends to skip certain fields in the worksheet and is also longer.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now