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
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi & welcome to MrExcel.
It needs to be like
VBA Code:
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
 
Upvote 0
Solution
If you have the "THEN" portion of the "IF...THEN" on the same line as the "IF", then you do not use an "END IF" statement.
You only use that if your "IF...THEN" covers more than one line (i.e. the "THEN" portion is on the next row, not the same row as the "IF").
 
Upvote 0
What if the code
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
Has the value change 65 times?
So a4.value =“3426”
How would i write that code to make it work correctly ?

Thank you for assistance
 
Upvote 0
What if the code
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
Has the value change 65 times?
So a4.value =“3426”
How would i write that code to make it work correctly ?

Thank you for assistance
So if i work on the sheet and i enter a value in a4 the code has to copy that and paste it in the correct cell on the next sheet ?
 
Upvote 0
So if i work on the sheet and i enter a value in a4 the code has to copy that and paste it in the correct cell on the next sheet ?
The paste value on the next sheet trend will change to the cell next to that number 3624
 
Upvote 0
Here is the code I am struggeling with please assist me
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
If Range("a4").Value = "903" Then
Range("C4").Select
Selection.Copy
Sheets("Trend").Select
Range("C5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If

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

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

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

Please assist in this, the value a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, and a16 changes 65 times with different numbers.
 
Upvote 0
As this is a totally different question, you will need to start a new thread. Thanks
 
Upvote 0
Hi & welcome to MrExcel.
It needs to be like
VBA Code:
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?
 
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
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

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