0

I am working on a VBA Macro for a budget sheet. When it copies data to cell B30 I want it to look at the cell and if there is data in the cell move to B31 and so on. However, when it gets to cell B41 I want it to throw up and error message. How would I go about writing this code?

Sheets("Budget with Revenue 2017-Test").Select
Range("B18:I18").Select
Application.CutCopyMode = False
Selection.Copy
Range("B22").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
Range("Table2940[[Sum of Revenue]:[Sum of Savings]]").Select
Application.CutCopyMode = False
Selection.Copy
Range("B30").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
Range("B21:I22").Select
Range("I21").Activate
Application.CutCopyMode = False
Selection.ClearContents
Range("B14:H14").Select
Range("H14").Activate
Selection.ClearContents
Range("J2:J3").Select
Selection.ClearContents
Range("G2").Select
Selection.ClearContents
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
RainJ9
  • 55
  • 1
  • 1
  • 6
  • I *highly* suggest looking in to [how to avoid using `.Select`/`.Activate`](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros). Not only will it cut down the code, it'll help you learn how to use variables and loops. Do you literally need to know when `B41` is reached? With your current code, you can add this wherever you need the message to show (`//` means a new line): `If Activecell.Address = "$B$31" Then // MsgBox("Error!") // Exit Sub // End If`. – BruceWayne Mar 15 '17 at 00:46
  • B41 is an extra expense field for that table. After B41 cell the table uses a SUM function and then ends. – RainJ9 Mar 15 '17 at 00:53

0 Answers0