Home > Mobile >  if range("a1").value is blank then copy range("a2") or give me a msgbox that val
if range("a1").value is blank then copy range("a2") or give me a msgbox that val

Time:10-18

Sub If_Test1()

If Range("a1").Value = " " Then
   Range("a2").Select

ElseIf Range("a2").Value <> "" Then
       Range("a2").Copy

Else

MsgBox "C9 & E9 are Blank please check"


End If


End Sub

CodePudding user response:

  1. Put "" except " " in condition as If Range("a1").Value = "" Then Range("a2").Select because " " doesn't mean a blank cell

  2. except If Range("a1").Value = "" Then Range("a2").Select I'd prefer If Len(Range("a1"))>0 Then Range("a2").Select

  3. Also you can use If IsEmpty(Range("A1")) = True Then Range("A2").Select

CodePudding user response:

Thank you myself

Sub Test1()

If Worksheets("sheet1").Cells(1, 1).Value = "" Then

Worksheets("sheet1").Cells(2, 1).Copy

Else: Range("a1").Copy

End If Range("D3").PasteSpecial xlPasteValues

Activeselection = False

End Sub

  •  Tags:  
  • vba
  • Related