end if with blocked if

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Please help me with this code i am new to this and I am trying to do this on my own to no avail.
here is my code that will not work please asist

If Range("a4").Value = "902" Then Range("C4").Select
Selection.Copy
Sheets("Trend").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,385
Office Version
  1. 365
Platform
  1. Windows
Hi @Fluff

Quick question... I know thread is answered but should the line

VBA Code:
Range("C4").Select

after

VBA Code:
Sheets("Trend").Select

not be like

VBA Code:
ActiveSheet.Range("C4").Select

to prevent a run-time error?
I don't think so.

If you leave off the sheet reference, "ActiveSheet" is implied/assumed.
If you have multiple sheets and really want to error proof, use the actual sheet name in the reference, and not ActiveSheet.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,174
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
If you leave off the sheet reference, "ActiveSheet" is implied/assumed.
Depends where the code is - if it's in a worksheet module, it would cause an error as you'd be trying to select a range on a sheet that wasn't active any longer.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,385
Office Version
  1. 365
Platform
  1. Windows
Depends where the code is - if it's in a worksheet module, it would cause an error as you'd be trying to select a range on a sheet that wasn't active any longer.
Good point. Thanks for the clarification.
 

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Don't really need any selecting at all:

VBA Code:
If Range("a4").Value = "902" Then
    Sheets("Trend").Range("C4").Value = Range("C4").Value
End If
Hi There

I like your code its nice and simple but i have an issue

As soon as you put more than one number in to copy and paste it only copies one?

Any ideas?

See code
If Range("a4").Value = "902" Then
Sheets("Trend").Range("C4").Value = Range("C4").Value
End If
 

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I am sorry i am
An idiot. Your code works perfect. Thank you for taking the time to show this code. I am new to this and are trying to something unique. Thank you again your code is working perfectly.
 

Forum statistics

Threads
1,137,114
Messages
5,679,708
Members
419,852
Latest member
ddewaard17

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
Top