How to use "AND" after THEN statement

Eyeson15

Board Regular
Joined
Apr 30, 2015
Messages
201
I have been using this below code.
It basically copies the value from cell H5 everytime it changes to the first empty cell in column N.
The problem is I need to copy H5 and I5 when H5 changes.
I have tried adding AND like this:

...Then sh.Range("N" & Range("N" & Rows.Count).End(xlUp).Row + 1).Value = sh.Range("H5") And sh.Range("O" & Range("O" & Rows.Count).End(xlUp).Row + 1).Value = sh.Range("I5")

this doesnt work.? Can anyone please enlighten me?

Code:
Sub Update(ByVal sh As Object)

    On Error GoTo exitsub
    Application.EnableEvents = False
    Sheets("Focus").Range("R1").Formula = "=$H$5"
    
    If (sh.Range("N" & Range("N" & Rows.Count).End(xlUp).Row).Value <> sh.Range("H5") And sh.Range("H5").Value <> "") Then sh.Range("N" & Range("N" & Rows.Count).End(xlUp).Row + 1).Value = sh.Range("H5")
    
exitsub:

    Application.EnableEvents = True
    
End Sub

James
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
where are you copying I5 to?
 
Upvote 0
Hi there
The first empty cell in column N.
So when H5 changes, H5 goes to empty cell in column N while I5 goes to empty cell in column O
 
Upvote 0
Try this.
Code:
sh.Range("N" & Range("N" & Rows.Count).End(xlUp).Row + 1).Resize,2).Value = sh.Range("H5").Resize(,2).Value
 
Upvote 0
Do you mean something like:
Code:
 If (sh.Range("N" & Range("N" & Rows.Count).End(xlUp).Row).Value <> sh.Range("H5") And sh.Range("H5").Value <> "") Then
sh.Range("N" & Range("N" & Rows.Count).End(xlUp).Row + 1).Value = sh.Range("H5") 
sh.Range("O" & Range("O" & Rows.Count).End(xlUp).Row + 1).Value = sh.Range("I5")
End If
 
Upvote 0
Try this.
Code:
sh.Range("N" & Rows.Count).End(xlUp).Offset(1).Resize(, 2).Value = sh.Range("H5").Resize(, 2).Value
 
Upvote 0
Thank you Barry and Norie
Both worked PERFECTLY. So simple..!
Saved me alot of headache. I will think about you both before I sleep tonight.
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,198
Latest member
MhammadishaqKhan

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