VBA If a cell contains a value in a range of cells ensure that another cell in a different column in the same row also has a value

DavyJones90

Board Regular
Joined
Feb 23, 2022
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Hello I have a Macro which automatically creates a PDF of an Analysis sheet, now the problem I am facing is that I want to build in a check step to ensure the full analysis was completed fully,

So my idea is something like this


VBA Code:
'(FAKE CODE)
IF a cell in Range("N4:N14") <> 0 OR "" check the the same Row in Column("I")  and ensure that it's value is more than 0 OR "" Then

MsgBox "PDF Could not be created because a Value in Coloumn I is missing "

Else
ThisWorkbook.Worksheets("AUTO ENTRY POINTS").Range("O4").NumberFormat = "dd/mm/yy"
    ThisWorkbook.Worksheets("AUTO ENTRY POINTS").Range("O4").Value = Date
    ThisWorkbook.Worksheets("AUTO ENTRY POINTS").Cells.Copy
    newWorkbook.Worksheets(1).Cells.PasteSpecial Paste:=xlPasteFormats
    newWorkbook.Worksheets(1).Cells.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    newWorkbook.Worksheets(1).Range("A:A").ClearContents
    newWorkbook.Worksheets(1).Name = "Values"
    
    Application.CutCopyMode = False
    Application.CutCopyMode = True
    newWorkbook.Sheets.Add.Name = "XL FILE"
    newWorkbook.Sheets("XL FILE").Move After:=Sheets("Values")
    ThisWorkbook.Worksheets("XL FILE").Cells.Copy
    newWorkbook.Worksheets("XL FILE").Cells.PasteSpecial Paste:=xlPasteFormats
    newWorkbook.Worksheets("XL FILE").Cells.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    
    Application.CutCopyMode = False

    newWorkbook.SaveAs newWbPath
End if

Thanks in advance!
 
OK I dont understand how or why it works, but this is what I changed and it works, Thanks for your help!


VBA Code:
            If Val(aCell.Value2) <> Empty Then
                If Not .Range("I" & aCell.Row).Value2 * 10 > 0 Then

What you are doing is checking if the cell is not empty. That will not check if the value is greater than 0. What if you typed a string instead of a number? Also if there is a space in your cell, Empty will return False. If you are 100% sure that the cell will always have numeric values then you can use

VBA Code:
If Len(Trim(aCell.Value2)) <> 0 Then

instead of

VBA Code:
If Val(aCell.Value2) <> Empty Then
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
That means the cell doesn't have a numeric value greater than 0 (0.3). Try this as well

VBA Code:
?Val(.Range("I" & aCell.Row).Value2) = 0.3
I think a spent the entire day trial and erroring every possible variation of this sentence and I am just glad is works now, so I leave it, but I am replacing the Empty part as you said. Although it is not possible to make spaces or anything but a numeric value in this field, as the values can only be selected by a drop down menu

Thanks again, I wouldn't have managed without your help
 
Upvote 0

Forum statistics

Threads
1,215,529
Messages
6,125,344
Members
449,219
Latest member
Smiqer

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