end if with blocked if

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
31
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
 
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.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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.
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

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