VBA Code - Add another Range to to copy and paste based on two ranges

dbnfl

Board Regular
Joined
Aug 11, 2019
Messages
59
Hello,

I have t below code and I need to add another range.

For Each c In sh1.Range("AT5", sh1.Range("AT" & Rows.Count).End(xlUp)) - I want to add range ("AR5", sh1.Range("AR" & Rows.Count)
Set f = sh2.Range("O:O").Find(c.Value, , xlValues, xlWhole) - I want to add range ("M:M").Find(c.Value, , xlValues, xlWhole)

I also need to change this part of code. As I update sheets("Wharf Schedules") if no match is found I want cell on sheets("Data") to not change. At present if I update sheets("Wharf Schedules") and the Vessel Name and Voyage Number are not found it deletes data from cell.

'If Not f Is Nothing Then'

Sub Import_Vessel_Availablility_Update()

Dim c As Range, f As Range, sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Sheets("Data")
Set sh2 = Sheets("Wharf Schedules")
For Each c In sh1.Range("AT5", sh1.Range("AT" & Rows.Count).End(xlUp))
If c.Value <> "" Then
Set f = sh2.Range("O:O").Find(c.Value, , xlValues, xlWhole)
If Not f Is Nothing Then
sh1.Range("AU" & c.Row) = sh2.Range("Q" & f.Row)
sh1.Range("AV" & c.Row) = sh2.Range("R" & f.Row)
sh1.Range("AW" & c.Row) = sh2.Range("S" & f.Row)
End If
End If
Next
MsgBox "Vessel Availablility details have been updated in main Data Sheet"
End Sub

Thank you in advance
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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