0

I'm trying to edit the VBA for one of my workbooks so that If there is a value in column A, then a value for column C is required or else the file won't save, but i'm having some trouble with this. I can get excel to check a cell for any input and require it have input, but I need it to check if a different cell has an input before requiring input. This is because not all of the lines in my spreadsheet will be used all of the time, but some people forget to put very important pieces of information in the spreadsheet which throws some of our balances off.

An SKU is entered on the sheet when we switch to a new one, and I want the program to make sure there is an amount of product in a given cell every time a new SKU is entered onto the sheet.

Thanks.

  • I'm not sure if excel can do this, sounds more like a human issue to me. Train your users to not forget "very important pieces of information in the spreadsheet", as you say, and you'll be better off all-around. – Wutnaut Jun 2 '14 at 15:29
1

Something like this would work, it reminds the user to enter something in quantity. Put it in the code for the worksheet.

Sub worksheet_change(ByVal target As Range)

If Not Intersect(target, Range("A:A")) Is Nothing And target.Value <> "" Then

    If target.Offset(, 2) = "" Then
        MsgBox ("For the SKU you just entered, be sure to enter a quantity in Column C")
    End If

End If

End Sub

You can change it so it takes an input or anything else if you'd like. Like this -

Sub worksheet_change(ByVal target As Range)

If Not Intersect(target, Range("A:A")) Is Nothing And target.Value <> "" Then

    If target.Offset(, 2) = "" Then
        target.Offset(, 2) = InputBox("How many of these are there?")
    End If

End If

End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.