Adding IF statement to this VBA code?

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
This is the code I used which copies the information from sheets("Customer Info") into "Sheet1"

VBA Code:
Sub CopyOrder()
  Dim sh1 As Worksheet, sh3 As Worksheet
  Dim i As Long
 
  Set sh1 = Sheets("Customer Info")
  For i = 2 To sh1.Range("A" & Rows.Count).End(3).Row
    Sheets("Sheet1").Copy after:=Sheets(Sheets.Count)
    Set sh3 = ActiveSheet
    sh3.Name = "Order" & i - 5
    sh3.Range("B4").Value = Date
    sh3.Range("B6").Value = Date + 1
    sh3.Range("B8").Value = "No"
    sh3.Range("B11").Value = sh1.Range("R" & i).Value
    sh3.Range("B19").Value = sh1.Range("B" & i).Value
    sh3.Range("B14").Value = sh1.Range("D" & i).Value
    sh3.Range("B15").Value = sh1.Range("E" & i).Value
    sh3.Range("B16").Value = sh1.Range("F" & i).Value
    sh3.Range("B20").Value = sh1.Range("H" & i).Value
    sh3.Range("B34").Value = "Jane Doe"
    sh3.Range("B38").Value = "John Doe"
    sh3.Range("E14").Value = sh1.Range("O" & i).Value
    sh3.Range("E15").Value = sh1.Range("P" & i).Value
    sh3.Range("E16").Value = sh1.Range("Q" & i).Value
  
  Next
End Sub

Some of the customers on the sheet "Customer Information" will have additional orders. How could I make an additional macro which will copy information from "Customer Info" Into "sheet2" IF column H is not blank?

VBA Code:
Range("H:H").Value<>""

Something like that perhaps?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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