Hi, everyone! I'm new to VBA and have learned a lot from lurking on this site.
I am trying to figure out how to modify the VBA script below so that it adds the value entered only to blank cells. Because the data I'm working with is automatically collected by dataloggers, there are blank cells sometimes that shouldn't have values added.
I can't seem to get it working so that it's only adding Num to non-blank cells. Would appreciate any help!
I am trying to figure out how to modify the VBA script below so that it adds the value entered only to blank cells. Because the data I'm working with is automatically collected by dataloggers, there are blank cells sometimes that shouldn't have values added.
I can't seem to get it working so that it's only adding Num to non-blank cells. Would appreciate any help!
Code:
Sub MarginOfError()
Dim WS As Worksheet
Dim rngSel As Range
Dim Num As Double
Dim i As Long
Dim j As Long
Dim lRows As Long
Dim lCols As Long
Dim Arr() As Variant
Dim strPrompt As String
Columns("D").Select
Set rngSel = Selection
lRows = rngSel.Rows.Count
lCols = rngSel.Columns.Count
strPrompt = "Enter number to add to selected cells"
On Error Resume Next
Num = InputBox(strPrompt, "Margin of Error", 0)
If Num <> 0 Then
If rngSel.Count = 1 Then
rngSel = rngSel + Num
Else
Arr = rngSel
For i = 1 To lRows
For j = 1 To lCols
Arr(i, j) = Arr(i, j) + Num
Next j
Next i
rngSel.Value = Arr
End If
End If
Dim SaveToDirectory As String
Dim CurrentWorkbook As String
Dim CurrentFormat As Long
CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat
SaveToDirectory = "S:\Macro\"
For Each WS In ThisWorkbook.Worksheets
Sheets(WS.Name).Copy
ActiveWorkbook.SaveAs Filename:=SaveToDirectory & WS.Name & ".csv", FileFormat:=xlCSV
ActiveWorkbook.Close savechanges:=False
ThisWorkbook.Activate
Next
End Sub