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
 

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.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
60,423
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,430
Office Version
  1. 365
Platform
  1. Windows
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").
 

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows

ADVERTISEMENT

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 ?
 

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows

ADVERTISEMENT

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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
60,423
Office Version
  1. 365
Platform
  1. Windows
As this is a totally different question, you will need to start a new thread. Thanks
 

Jimmypop

Board Regular
Joined
Sep 12, 2013
Messages
123
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?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,192
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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
 

Forum statistics

Threads
1,137,349
Messages
5,680,971
Members
419,947
Latest member
cchristian6

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